0
Can someone explain this for me? Why the answer will be 10?
3 Respostas
+ 3
1+(1+1)+(1+1+1)+(1+1+1+1)
+ 2
@Calvin
@Justin Hill
Thanks alot!
+ 1
count = 0
for i in range (5):
for j in range (i):
count +=1
Everytime Your loop runs, it runs the second loop however many times the first loop is currently on. so
1st run of i runs j 0 times.
count=0
2nd run of i runs j 1 time.
count=1
3rd run of i runs j 2 times.
count=2
count=3
4th run of i runs j 3 times.
count=4
count=5
count=6
and your final run of i runs j 4 times.
count=7
count=8
count=9
count=10
Run this code. I often use print functions to see what is happening. Maybe it will help clear it up
count = 0
for i in range (5):
print("i = {}".format(i))
for j in range (i):
count +=1
print("count = {}".format(count))