Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 218
Image: ubuntu2004
Kernel: Python 3 (system-wide)
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