4.11 Lesson Practice
Question: 4.1 Lesson Practice
We use loops to:
Answer: Repeat blocks of code
Question: 4.1 Lesson Practice
Consider the following code:
num = int(input(“Enter a number, negative to stop”))
while (num >= 0):
print (“You entered: “ + str(num))
num = int(input(“Enter a number, negative to stop”))
print (“Done.”)
What is wrong?
Answer: The line num = int(input(“Enter a number, negative to stop”)) should be indented so it is inside the loop
Question: 4.1 Lesson Practice
Answer: Complete the activity.
Question: 4.1 Code Practice
Answer: name = input(“Please enter a name, Nope to end “)
while (name != “Nope”):
print (“Nice to meet you “ + name)
name = input(“Please enter a name, Nope to end “)
print (“Done”)
Question: 4.2 Lesson Practice
What is output? Select all that apply.
c = 0
while (c < 10):
c = c + 5
print (c)
Answer: 5 and 10
Question: 4.2 Lesson Practice
What is output? Select all that apply.
c = 3
while (c < 10):
c = c + 2
print (c)
Answer: 5, 7, 9 and 11
Question: 4.2 Lesson Practice
What is output?
c = 1
sum = 0
while (c < 10):
c = c + 3
sum = sum + c
print (sum)
Answer: 21
Question: 4.2 Lesson Practice
What should be entered to make the loop print
60
70
80
x = 50
while (x < 80):
x = x + ____
print (x)
Answer: 10
Question: 4.2 Code Practice: Question 1
Answer: sum = 0
count = 0
while (sum <= 100):
count +=1
num = int(input(“Enter a number: “))
sum += num
print(“Sum: “ + str(sum))
print(“Numbers entered: “ + str(count))
Question: pet = input(“What pet do you have?”)
count = 0
while (pet!= “rock”):
count +=1
print (“You have a “ + str(pet) + “ with a total of “ + str(count) + “ pet(s)”)
pet = input(“Enter pet: “)
Answer: 4.2 Code Practice: Question 2