Professional Documents
Culture Documents
in Python
•1
Frequently syntax errors
Notice a single space at the start of the line
Notice IF instead of if
Notice If instead of if
•2
Conditional execution (from previous lecture)
condition
Indentation is important
Use a single Tab or four
spaces for each indentation
level
•3
•4
•5
Nested Conditionals
IF
(outer IF condition)
Nested IF
(inner IF condition)
•6
•7
•8
•9
Roots of Quadratic Equations
•10
Roots of Quadratic Equations (Python Code)
•11
x2-4x+4=0
x2-2x+4=0
•12
If with or and and
•13
Iteration
•14
Iteration (while)
•15
This code squares the value of x by repetitive addition
•16
The for Loop
for x in range(0,10,1)
for x in range(0,10) Similar to DO loop in Fortran
for x in range(10) •17
The for Loop
•18
The for Loop
>>> for x in range(0,10,1): 0
print x 1
2
>>> for x in range(0,10): 3
print x 4
5
>>> for x in range(10): 6
print x 7
8
9
•19
The for Loop
•21
The for Loop Python Code for even/odd
numbers from 0 to 10
•22
10
𝑥 = 1 + 2 + 3 + 4 + 5 + 6 … 10
𝑥=1
10
𝑥 2 = 1 + 22 + 32 + 42 + 52 + 62 …
𝑥=1
•23
Good Programming
Turn off your other activities in your mind when
you Turn on a computer for programming
Hypnotize a computer
•24