Open with one click!
In [1]:
numbers=[1,2,3,4,5] total=0 for i in range (len(numbers)): total+=numbers[i] print("sum of numbers using for loop: {}".format(total))
sum of numbers using for loop: 15
In [2]:
total=0 length=len(numbers) while(length): total+=numbers[length-1] length-=1 print("sum of numbers using while loop: {}".format(total))
sum of numbers using while loop: 15
In [ ]: