



































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Stepp; Class: COMPUTER PRGRMNG I; Subject: Computer Science and Engineering; University: University of Washington - Seattle; Term: Unknown 2008;
Typology: Study notes
1 / 43
This page cannot be seen from the preview
Don't miss anything!




































Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides.
Except where otherwise noted, this work is licensed under:http://creativecommons.org/licenses/by-nc-sa/3.
-^
-^
-^
-^
-^
-^
-^
-^
-^ script
: A program meant for use in small/medium projects
-^
Windows: •^
Download Python fromhttp://www.python.org
-^
Install Python.
-^
Run
Idle
from the Start Menu.
Mac OS X: •^
Python is already installed.
-^
Open a terminal and run
python
or run Idle from Finder. Linux: •^
Chances are you already have
-^
Chances are you already have Python installed.
To check, run
python
from the terminal.
-^
If not, install from yourdistribution's package system.
Note:
For step by step installation instructions, see the course web site.
-^
-^
-^ Syntax:
#^ comment text (one line) swallows2.py^1
# Suzy Student, CSE 142, Fall 2097 1 2 3 4 5 6
# Suzy Student, CSE 142, Fall 2097 # This program prints important messages. print "Hello, world!"print
# blank line
print "Suppose two swallows "carry" it together."print 'African or "European" swallows?'
-^
Example:
-^
add, subtract/negate, multiply, divide
exponentiate
modulus, a.k.a. remainder
-^
have a higher precedence than
is^
is
-^
-^
name
expression
x^
gpa
x^
5
gpa
x^
is
-^
print "Subtotal:"print 38 + 40 + 30print "Tax:"print (38 + 40 + 30) * .09 print "Tip:" print "Tip:" print (38 + 40 + 30) * .15print "Total:"print 38 + 40 + 30 + (38 + 40 + 30) * .15 + (38 + 40 + 30) *.
-^
command
value
command
value
,^ value
value
-^
-^
sqrt(
sqrt(
x^ =
sqrt(
x^
+^ sqrt(16)
Function name
Description
abs(
value
)^
absolute value
ceil(
value
)^
rounds up
cos(
value
)^
cosine, in radians
floor(
value
)^
rounds down
log10(
value
)^
logarithm, base 10
max(
value
,^ value
)^
larger of two values
Constant
Description e^
2.7182818...
pi^
3.1415926...
-^
math
import
max(
value
,^ value
)^
larger of two values
min(
value
,^ value
)^
smaller of two values
round(
value
)^
nearest whole number
sin(
value
)^
sine, in radians
sqrt(
value
)^
square root
-^
condition
statements
-^ Example: -^ Example:^ gpa
= input("What
is
your
GPA?
")
if gpa
>^
2.0: print
"Your
application
is
accepted."