Quiz 3 Flashcards
What is the output?
word = “Anaconda”
for letter in word:
print (letter, word)
A Anaconda n Anaconda a Anaconda c Anaconda o Anaconda n Anaconda d Anaconda a Anaconda
What is the output? count = 0 while count <5 print(count) count = count + 1
0 1 2 3 4
What is the output? num = 5 while num > 0 num = num - 1 print (num)
4 3 2 1 0 -1
What is the output? letter_count = "" for char in "12345": letter_count = letter_count +char print(count)
1 12 123 1234 12345
What is the output?
saying = “Cyrus Turnbul.” #line1
print (saying [4:9]) #line 2
s Tur
What type of loop is a count controlled loop?
for loop
What type of loop uses a Boolean statement to control the loop?
while loop
Each repetition of a loop is known as a(n)_________.
iteration
The *= operator is an example of a(n) __________ operator.
augmented assignment
The *= operator is an example of a(n) __________ operator.
augmented assignment operator
Write a while loop that counts from two to ten by twos. The results of your loop will match the following: 2 4 6 8 10
X = 2
while X <= 10:
print(format(X, “.0f”))
X += 2
How many times will “Hello, It’s me.” be printed in the following program?
count = 10
while count >=10:
print(“Hello, It’s me.”)
infinite
What will the following code display?
for number in range(6):
print(number)
0 1 2 3 4 5
What will the following code display?
for number in range(2,6):
print(number, end = “ “)
2 3 4 5
What will the following code display?
for number in range(0, 501, 100):
print(number)
0 100 200 300 400 500
What will the following code display?
for i in range(7,12):
print(i, end = ‘ ‘)
7 8 9 10 11
Write a for loop that will print the numbers between 6 and 100 that are evenly divisible by 2. Include 6 and 100.
for x in range (6,100,2):
Write a program that has the user enter a positive integer greater than one. Using a for loop print each integer from that number down to but not including 1:
x = int(input(“Please enter a number greater than 1: “))
for y in range(1,x):
print(x)
x = x-1
A(n) __________ variable keeps a running total.
a.Sentinel b.Sum c.Total d.Accumulator
and, or and not are ___________ operators.
logical operators.
When a program compares characters, it actually compares the __________ codes
ASCII
Write a program that has the user enter an int. Using a for loop print each int from that number down to but not including 0
x = int(input(“Please enter an integer: “))
for y in range(0,x):
print(x)
x = x-1
What is the output?
word = “John Boy”
for ch in word:
print(ch)
J
o
h
n
B
o
y
What is the output?
for alpha in “abet”:
print(“Hooray!”)
Hooray!
Hooray!
Hooray!
Hooray!
What is the output?
for letter in “abcdefg”:
if letter in “aeiou”
print(letter)
a
e
What is the output? word = “Mississippi” for letter in word: if letter != “s”and letter !=“p”: print(letter)
M i i i i
num = 0
while num < 10:
print(num)
num = num + 2
0 2 4 5 8