Write a Python program that continuously asks for numbers from the user until they enter 0. After receiving a 0, the program should print the sum of all the numbers entered so far.
Example 1:
Input: 5, 10, 15, 20, 0 Output: 50
Example 2:
Input: -5, 15, -10, 20, 0 Output: 20
This problem requires a while loop that will continue until a specific condition is met. In this case, the condition is the user entering a 0.
total = 0
number = int(input("Enter a number: "))
while number != 0:
total += number
number = int(input("Enter a number: "))
print("Sum of all numbers:", total)
Unlock AI & Data Science treasures. Log in!