Answers
4.1 Lesson Practice
We use loops to: - answer Repeat blocks of code
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
4.1 Lesson Practice - answer Complete the activity.
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")
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
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
4.2 Lesson Practice
, What is output?
c=1
sum = 0
while (c < 10):
c=c+3
sum = sum + c
print (sum) - answer 21
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
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))
4.2 Code Practice: Question 2 - answer 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: ")
4.3 Lesson Practice
Consider the following code:
x = int(input ("Enter a value: "))
c=0
sum = 0
while (c < 10):
x = int(input ("Enter a value: "))
c=c+1
sum = sum + x