Working on exercises (a few notes first)‏. Comments Sometimes you want to make a comment in the Python code, to remind you what’s going on. Python ignores.

Slides:



Advertisements
Similar presentations
Python November 14, Unit 7. Python Hello world, in class.
Advertisements

 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
XP Tutorial 5New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Designing a Web Site with Frames Using Frames to Display Multiple Web Pages Tutorial.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Recitation 1 Programming for Engineers in Python.
Fundamentals of Python: From First Programs Through Data Structures
28/08/2015SJF L31 F21SF Software Engineering Foundations ASSUMPTIONS AND TESTING Monica Farrow EM G30 Material available on Vision.
Python programs How can I run a program? Input and output.
Python Programming Fundamentals
“Everything Else”. Find all substrings We’ve learned how to find the first location of a string in another string with find. What about finding all matches?
An Introduction to Textual Programming
The if statement and files. The if statement Do a code block only when something is True if test: print "The expression is true"
Introduction to Python
Lists in Python.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Sorting and Modules. Sorting Lists have a sort method >>> L1 = ["this", "is", "a", "list", "of", "words"] >>> print L1 ['this', 'is', 'a', 'list', 'of',
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Introducing Python CS 4320, SPRING Format: Field widths and Alignment The string representation of a value can be padded out to a specific width.
Computer Science 101 Introduction to Programming.
Working on exercises (a few notes first). Comments Sometimes you want to make a comment in the Python code, to remind you what’s going on. Python ignores.
Variables and Expressions CMSC 201 Chang (rev )
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
Functions. Built-in functions You’ve used several functions already >>> len("ATGGTCA")‏ 7 >>> abs(-6)‏ 6 >>> float("3.1415")‏ >>>
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
Variables, Expressions, and Statements
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
ECS 15 Variables. Outline  Using IDLE  Building blocks of programs: Text Numbers Variables!  Writing a program  Running the program.
Math, Data Types. Python Math Operations OperationOperator Addition + Subtraction – Multiplication * Division (floating point) / Division (integer) //
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
Last Week Modules Save functions to a file, e.g., filename.py The file filename.py is a module We can use the functions in filename.py by importing it.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
1 CSC 221: Introduction to Programming Fall 2011 Input & file processing  input vs. raw_input  files: input, output  opening & closing files  read(),
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python, Class 2 Karsten Hokamp, PhD Genetics TCD, 17/11/2015.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
1 Project 3 String Methods. Project 3: String Methods Write a program to do the following string manipulations: Prompt the user to enter a phrase and.
PYTHON VARIABLES : CHAPTER 2 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
Dayu Zhang 9/10/2014 Lab03. Outline Brief Review of the 4 Steps in Hello.cpp Example Understand endl and \n Understand Comment Programming Exercise -
Thinking about programming Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
Introduction to Programming Python Lab 8: Loops 26 February PythonLab8 lecture slides.ppt Ping Brennan
Getting Started With Python Brendan Routledge
Day 22, Slide 1 CSE 103 Day 22 Non-students: Please logout by 10:12. Students:
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
ENGINEERING 1D04 Tutorial 2. What we’re doing today More on Strings String input Strings as lists String indexing Slice Concatenation and Repetition len()
Few More Math Operators
Introduction to Programming
Whatcha doin'? Aims: To start using Python. To understand loops.
Introduction to Programming
Data Types and Conversions, Input from the Keyboard
(optional - but then again, all of these are optional)
Presented By S.Yamuna AP/IT
Introduction to Programming
Manipulating Text In today’s lesson we will look at:
Introduction to Programming
Introduction to Programming
Python programming exercise
CHAPTER 3: String And Numeric Data In Python
Functions continued.
Introduction to Programming
“Everything Else”.
Introduction to Programming
Hardware is… Software is…
Presentation transcript:

Working on exercises (a few notes first)‏

Comments Sometimes you want to make a comment in the Python code, to remind you what’s going on. Python ignores everything from a # to the end of the line. Feel free to write anything you want. # This is ignored by Python. print "Hello, Cape Town" # And so is this. # n = 0 # for line in open("filename"): # print n, line # n = n + 1

IDLE helps out To comment many lines: Select some lines then choose “Format” from the pull-down menu. Choose “Comment Out Region” from the list that appears. To uncomment many lines: Use “Format” -> “Uncomment Region” To move lines to the right: Use “Format” -> “Indent Region” To move lines to the left, “Dedent Region”

Python and division Python integers are “closed” under division That’s a special way of saying that an integer divided by another integer using Python will always return an integer. “integers” are a special way of saying “whole numbers,” that is, numbers without a fraction. Mathematicians have lots of special names! (And so do biologists. And programmers.☺)‏

Python rounds down When the result is a fraction, Python rounds it down to the next smallest intege r >>> 20 / 10 2 >>> 15 / 10 1 >>> 10 / 10 1 >>> 9 / 10 0 >>>

How to fix it The author of Python now says this behavior was a mistake. It should work like people expect. Instead, you need to convert one of the integers into a floating point number >>> 15 / float(10)‏ 1.5 >>>

More examples >>> 20 / float(10)‏ 2.0 >>> 15 / float(10)‏ 1.5 >>> 10 / float(10)‏ 1.0 >>> 9 / float(10)‏ >>>

Why do you need to know about this? Previous assignment asked you to find all sequences with more than 50% GC content >>> G = 120 >>> C = 33 >>> length = 400 >>> (G + C) / length 0 >>> (G + C) / float(length)‏ >>>

Exercise 6 Look again at sequences.seq. Did your program assume only A, T, C, and G? For this exercise, count the number of sequences in that file which have some other letter. What might those mean? How does it affect your %GC calculations?

Exercise 7 Search by molecular weight From experiments you believe your DNA sequence has a molecular weight between and You think it might be in the database from yesterday, sequences.seq. For each sequence in that file which have a molecular weight in that range, print the molecular weight and the sequence. You might need the data table on the next page.

Molecular weights A = C = B = D = G = H = K = M = N = S = R = T = W = V = Y = X = I put a copy of these weights in the file weights.txt

Exercise 8 Verify that your program actually works. How? Here are some possibilities: Compare your results with others’. Create a small sequence file by hand where you know the weight. Compare your manual calculations to what your program found. Find a web site which does this. Compare. Find a published table of weights. Compare.....

Exercise 9 Modify your program from Exercise 8 to ask the user for the filename to use, the lower weight, and the upper weight. You will need the float function to convert the string from raw_input into a number. Redo exercises 8 and 9 with an input file Your program must get the filename and ranges from the user via raw_input and not by modifying your program.