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?
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?
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)