Mod 3 Flashcards
What is the output:
2==2.0
True
What is the output:
x = 10
if x == 10: print(x == 10) if x > 5: print(x > 5) if x < 10: print(x < 10) else: print("else")
True
True
else
What is the output:
x = “1”
if x == 1: print("one") elif x == "1": if int(x) > 1: print("two") elif int(x) < 1: print("three") else: print("four") if int(x) == 1: print("five") else: print("six")
four
five
x = 1 y = 1.0 z = "1"
if x == y: print("one") if y == int(z): print("two") elif x == y: print("three") else: print("four")
one
two
What is the output:
for i in range (2, 8, 3):
print(i)
2
5
What does break do in a loop?
Exits the loop. The program begins to execute the nearest instruction after the loops body
What does continue do in a loop?
Skips the current iteration and continues with the next.
What is the output: print("The break instruction:") for i in range(1, 6): if i == 3: break print("Inside the loop.", i) print("Outside the loop.")
The break instruction:
Inside the loop. 1
Inside the loop. 2
Outside the loop.
What is the output: print("The continue instruction:") for i in range(1, 6): if i == 3: continue print("Inside the loop.", i) print("Outside the loop.")
The continue instruction: Inside the loop. 1 Inside the loop. 2 Inside the loop. 4 Inside the loop. 5 Outside the loop.
What is the output: i = 1 while i < 5: print(i) i += 1 else: print("else:", i)
1 2 3 4 else: 5
What is the output: for i in range(5): print(i) else: print("else:", i)
0 1 2 3 4 else: 4
What type of loop executes a statement or a set of statements as long as a specified boolean condition is true?
while
What type of loop executes a set of statements many times, used to iterate over a sequence (often used with the range function)
for
In while and for loops the else clause executes after the loop finishes its execution as long as it has not been terminated by ____.
break
Provide the range function syntax
range(start, stop, step)
What is the output of:
for i in range(5):
print(i, end=” “)
0 1 2 3 4