Outline for October 3, 2012
Reading
: § 2
Simple assignment:
variable = expression
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
Input: input statement
input(prompt)
prints prompt, waits for user
When user hits enter, it returns what was typed as a string
Type converter functions
int
,
float
import
statement
import math
Example: program to compute the length of the hypotenuse of a right triangle [
hypotf.py
]
What is the math formula? (Pythagoras:
)
Steps in the program:
Ask user for length of two other sides
Compute hypotenuse, using math library’s square root function
Print result
Implementation (line by line)
Another form of the
import
statement
from math import sqrt
[
hypot.py
]
A PDF version is available here.
ECS 10, Basic Concepts of Computing
Fall Quarter 2012