Can anyone explain this in detail?

Viewed 43
num = 5

result = 1

for iterator in range(1, num+1):
   
     result = result * num

print(result)

I am new to python and don’t understand what is going on with this problem. What does (1,num+1) represent and how is the result being calculated?

1 Answers

range(start, stop, step) you are starting your iteration at 1, and stopping it at (num + 1) = 6 run this code and you will see how it is working. You are calculating one result, and then multiplying that result by num again, 5 times.

num = 5

result = 1

for iterator in range(1, num+1):
 result = result * num
 print(result)
Related