Outline for January 13, 2012
Reading:
§2
Python, files and shells
Python: programming
language
that you use to tell the computer what to do
Shell: what you can type Python statements directly into, to see what they do
IDLE: the program that
interprets
Python statements (executes the Python program)
File: type Python statements into this, and then have IDLE execute those statements by running the program in the file
Example: program to convert temperature \program{tempcvt.py}
Do we go from Fahrenheit to Celsius, Celsius to Fahrenheit, or both?
Go from Celsius to Fahrenheit
Steps in the program:
Ask user for temperature in Celsius
Convert to Fahrenheit (
F
= (9/5)
C
+ 32)
Print result in Fahrenheit
Implementation (line by line)
Type converter functions
int
,
float
,
str
Expressions
Operators
+
,
-
,
*
,
/
,
//
,
%
,
**
Precedence
Parentheses for grouping (
(
,
)
)
Exponentiation (
**
); associates right to left
Positive, negative (unary
+
,
-
)
Multiplication, division, integer division, remainder (
*+
,
/
,
//
,
%
)
Addition, subtraction (binary
+
,
-
)
In general, operators of equal precedence are evaluated from the left to the right (associativity); exception noted above
Simple assignment:
variable = expression
Input: input statement
input(prompt)
prints prompt, waits for user
When user hits enter, it returns what was typed as a string
A PDF version is available here.
ECS 10, Basic Concepts of Computing
Winter Quarter 2012