What are the 5 data types we've learned in this class? Give an example of each
int - 5
float - 5.0
boolean - True
string - "Hi"
list - ['I', 'love', 'girls', 'who', 'code']
In Python, what is the number that list and string indexing starts at?
0
What do these evaluate to (True or False)?
True and False
True or False
not True
False
True
False
What is the python syntax to write a for loop that loops through every item in the list my_list
for item in my_list:
What is the python syntax to write a while loop that prints âRemember an umbrella!â when it is raining?
raining = True
while raining:
print("Remember an umbrella!")
How do I assign the value 10 to the variable called num_coins?
num_coins = 10
What code would get the letter t from the variable fav_fruit?
fav_fruit = 'watermelon'
fav_fruit[2]
What does this evaluate to (True or False)?
x = True
y = False
z = True
(x and y) or (not y and z)
True
What is the value of ice_cream during the third time through the loop?
What gets printed during the third time through the loop?
flavors = ['Vanilla', 'Chocolate', 'Mint']
for ice_cream in flavors:
print(ice_cream.lower())
'Mint'
mint
How many times do we go through this while loop? What gets printed?
count = 0
while count < 5:
count += 1
print(count)
5 times
5
From before, I have
num_coins = 10
How do I update the variable num_coins to have 4 less than its previous value?
num_coins = num_coins - 4
How do I use list splicing to a get a list with only Wonder Woman and Black Panther?
superheroes = ["Spider-Man", "Wonder Woman", "Black Panther", "Batman"]
superheroes[1:3]
What will get printed?
temperature = 53
if temperature < 60:
print("Staying in the cave and roasting marshmallows!")
else:
print("Time to fly through the skies!")
Staying in the cave and roasting marshmallows!
What does the following code print?
for x in range(420, 425):
print(2)
2
2
2
2
2
What will get printed?
x = 1
total = 0
while x <= 5:
total += x
x += 1
print(total)
1
3
6
10
15
What's the code to ask the user "What is your favorite sport?" and store their answer in a variable called fav_sport
Hint: use input functions
fav_sport = input("What is your favorite sport?")
my_string = "Hi my name is KIRAN"
How do I print my_string with the lower case letters upper case and the upper case letters lower case (I want to swap cases)?
Hint: Google string methods
print(my_string.swapcase())
What will get printed?
temperature = 53
if temperature < 40:
print("Staying in the cave and roasting marshmallows!")
elif (temperature >= 40) and (temperature < 60):
print("A bit chilly, but time to fly through the skies!")
else:
print("Perfect weather for a dragon picnic!")
A bit chilly, but time to fly through the skies!
How do I write a for loop to print out 2 plus every element in the list nums?
nums = range(0, 20)
for i in nums:
print(2+i)
Write a while loop that prints "Hello!" 4 times.
Hint: Start with a variable count = 0
count = 0
while count < 4:
print("Hello!")
count += 1
What is the python syntax to store your three favorite snacksâ"chips", "cookies", and "popcorn"âin one variable called snacks
snacks = ["chips", "cookies", "popcorn"]
How do I add "Iron Man" to my list superheroes?
Hint: Google list methods
superheroes.append("Iron Man")
What will get printed?
temperature = 53
humidity = 75
if temperature < 60:
if humidity > 70:
print("Chilly but time to fly through the skies with an umbrella!")
else:
print("Chilly but time to fly through the skies!")
else:
print("Perfect weather for a dragon picnic!")
Chilly but time to fly through the skies with an umbrella!
Using a for loop, how do I print out the sum of all the elements in the list nums?
Hint: I need to declare an element before the for loop header
nums = range(0, 20)
sum = 0
for current_num in nums:
sum = sum + i
print(sum)
You set your alarm so you can snooze 3 times before you have to get up.
Write a while loop that checks if you can snooze your alarm and prints âWAKE UPPPPâ when you canât snooze it anymore.
Hints: (1) You need a variable to track how many times youâve snoozed. What should happen to that number every time you snooze?"
(2) While loops keep running as long as a condition is true... whatâs the condition for being allowed to snooze?"
snoozes_left = 3
while snoozes_left > 0:
print("Snoozing...")
snoozes_left -= 1
print("WAKE UPPPP!")