CoCalc Public Files2-22.ipynbOpen with one click!
Author: Marielys Bueno
Views : 118
Compute Environment: Ubuntu 20.04 (Default)
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 [ ]: