[ICSPP] W02 - Branching and Iteration
- strings are objects
- non-scalar objects
- enclose in single or double quotes
input/output
print
is used to output stuff to consoleinput
is used bind user input to a variable
comparison operators
>
,<
,==
,<=
,>=
,!=
logic operators
not a
a and b
a or b
control flow
- indentation matters in python for
if elif else
,for
andwhile
loops
if
conditionals
if <condition>:
<expression>
<expression>
...
elif <condition>:
<expression>
<expression>
...
else:
<expression>
<expression>
...
while
loops
while <condition>:
<expression>
<expression>
...
for
loops
for <variable> in range(<some_num>):
<expression>
<expression>
...
range(start,stop,step)
mysum = 0
for i in range(7,10):
mysum += i
print(mysum)
mysum = 0
for i in range(5,11,2):
mysum += i
print(mysum)
break
statement
- breaks out of conditional and loop statements’ flow
- end cycle or conditional early