CoCalc Public Filessum of values.ipynbOpen with one click!
Author: Julia Burnside
Views : 46
Compute Environment: Ubuntu 20.04 (Default)
In [1]:
print("Sum of values using for loop:") forSum = 0 for x in range(1, 6): print(x, end='') if x < 5: print("+", end='') forSum = forSum + x print("=", end='') print(forSum) print("Sum of values using while loop:") whileSum = 0 y = 1 while y < 6: print(y, end='') if y < 5: print("+", end='') whileSum = whileSum + y y = y + 1 print("=", end='') print(whileSum)
Sum of values using for loop: 1+2+3+4+5=15 Sum of values using while loop: 1+2+3+4+5=15