Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

what is the output of the following program? for num in range(4): print…

Question

what is the output of the following program?
for num in range(4):
print (num * 2)

Explanation:

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.

Answer:

0
2
4
6