QUESTION IMAGE
Question
what is the output of the following program?
for num in range(4):
print (num * 2)
Step1: Understand range function
The range(4) generates a sequence of numbers from 0 to 3 (inclusive of 0, exclusive of 4).
Step2: Iterate and calculate
When num = 0, num 2=02 = 0; when num = 1, num 2=12 = 2; when num = 2, num 2=22 = 4; when num = 3, num 2=32 = 6.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
0
2
4
6