means 'else if'
elif
number = int(5)
number2 = number + 5
print(number2)
10
counter = int(20)
counter = counter + 10
counter = counter - 5
counter = counter + 20
print(counter)
45
ask for a users age
age = int(input("what is your age: "))
repeats code based on a sequence
for loop
print(“why did the chicken cross the road?”)
print(“to get to the other side”
syntax error
name = “Single ladies”
Song = name + “ by Beyonce”
n/a
use a for loop to count to 10
for i in range(11):
print(i)
Causes a while loop to end
break statement
number1 = int(12)
number2 = int(12)
if number1 <= number2:
print("that’s great")
else:
print("that’s sad")
that's great
sunny = True
cloudy = False
laundryday = sunny and cloudy
print(laundryday)
laundryday = sunny or cloudy
print(laundryday)
False
True
add 1 to a counter everytime while loop goes around. Once the counter gets to 5, break.
counter = 0
while True:
counter = counter + 1
print(counter)
if counter ==5:
break
Repeated execution of one or more statements in a program
Iteration
i = 1
while i < 6:
print(i)
i += 1
1
2
3
4
5
num = 5
num2 = 50
while num <= num2:
num = num + 5
print("valid")
break
using an if statement, print "it's hot" if the user enters the temperature as greater than 20 degrees. If less than 20 degrees, print 'its not hot'
temp = int(input("what is the temperature"))
if temp > 20:
print("it's hot")
else:
print("it's not hot")
a series of elements
sequence
for i in range(6):
print(i)
0
1
2
3
4
5
for ele in range(len("Carleton")):
print(ele)
print("next part")
0
1
2
3
4
5
6
7
next part
In a while loop, ask user for city names. If the amount of letters is greater than 5, print valid. If less than 5, print invalid and break.
longstr = ""
while True:
text = input('enter a city name')
num_letters = len(text)
if num_letters > 5:
print("valid")
else:
print("invalid")
break