Question
1. We use loops ________________________. a) to test if more than one condition is true b) to do calculations on user input c) to repeat
1. We use loops ________________________.
a) | to test if more than one condition is true |
b) | to do calculations on user input |
c) | to repeat a section of code |
d) | as a gate to block off sections of code |
2. Consider the following code:
for i in range (x, y, z): print (i, end=" ")
What values for variables x, y, and z will produce the output below?
26 24 22 20 18 16 14 12 10 a) x = 26 y = 8 z = -2 b) x = 10 y = 28 z = -2 c) x = 26 y = 10 z = -2 d) x = 10 y = 28 z = 2
3. What is output by the following code?
for x in range (4): for y in range (3): print ("*", end=" ") print (" ")
a) * * * * * * * * * * * *
b) * * * * * * * * * * * * * * * * * * * *
c) * * * * * * * * * * * *
d) * * * * * * * * * * * * * * * * * * * *
4. Consider the following code:
start = int(input("Enter the starting number: ")) stop = int(input("Enter the ending number: "))
for i in range (start, stop): print (i, end=" ")
What variable is the loop control variable in this program?
a) i b) This loop doesn't have a control variable. c) start d) stop
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started