Edhesive 4.1 - 4.11 Questions & Answers
4.1 Lesson Practice
We use loops to: - ✔✔Repeat blocks of code
4.1 Lesson Practice
Consider the following code:
num = int(input("Enter a number, negative to stop"))
while (nu
...
Edhesive 4.1 - 4.11 Questions & Answers
4.1 Lesson Practice
We use loops to: - ✔✔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? - ✔✔The line num = int(input("Enter a number, negative to stop")) should be
indented so it is inside the loop
4.1 Lesson Practice - ✔✔Complete the activity.
4.1 Code Practice - ✔✔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) - ✔✔5 and 10
4.2 Lesson Practice
What is output? Select all that apply.
c = 3
while (c < 10):
c = c + 2
print (c) - ✔✔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) - ✔✔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) - ✔✔10
4.2 Code Practice: Question 1 - ✔✔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 - ✔✔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
print ("\n\nSum: " + str(sum))
What type of loop is it? - ✔✔Count variable loop
4.3 Lesson Practice
This code loops until the user types in 17. It finds and prints the sum of all even numbers
entered.
n = int(input ("Enter a number, 17 to stop."))
sum = 0
while (n != 17):
if (n % 2 == 0):
sum = sum + n
n = int(input ("Enter a number, 17 to stop."))
print ("Sum: " + str(sum))
This is an example of a(n) ____ loop - ✔✔user input
4.3 Lesson Practice
Suppose you change the program in the last problem so the user enters exactly 17 numbers.
The loop would then be an example of a(n) _____ loop - ✔✔count variable
4.3 Code Practice: Question 1 - ✔✔age = int(input("How old are you?"))
for i in range(1,age+1):
print("**HUG**")
4.3 Code Practice: Question 2 - ✔✔i = 3
while i <=21:
if i % 3 == 0:
print(i)
i+=1
4.5 Lesson Practice
We use loops: - ✔✔To repeat a section of code
4.5 Lesson Practice
What are the two ways to end a loop? (Select two answers.) - ✔✔Count variable
Using user input
4.5 Code Practice (dont reccomened using this) - ✔✔i = 0
while True:
word=input("Please enter the next word: ")
if word == "STOP":
break
i += 1
print("#{}:You entered{}".format(i, word))
print("All done. {} words entered.".format(i))
4.6 Lesson Practice
Range is an example of a ______________. - ✔✔function
4.6 Lesson Practice
The range function must have two parameters? - ✔✔False
4.6 Lesson Practice
What list of numbers is created by the following code?
range(8) - ✔✔0 1 2 3 4 5 6 7
4.6 Lesson Practice
What list of numbers is created by the following code?
range(4, 11) - ✔✔4 5
[Show More]