WAP that asks the user to enter a number one at a time until the user hits exactly zero (0).Display the sum of all the numbers that were entered by the user before hitting zero.
Question
WAP that asks the user to enter a number one at a time until the user hits exactly zero (0).Display the sum of all the numbers that were entered by the user before hitting zero.
Solution
Sure, here is a simple program that fulfills your requirements:
# Initialize sum to 0
total = 0
# Infinite loop
while True:
# Ask the user to enter a number
num = float(input("Enter a number: "))
# If the user enters 0, break the loop
if num == 0:
break
# Add the entered number to the total
total += num
# Print the total
print("The sum of all the numbers entered is:", total)
This program will keep asking the user to enter a number until they enter 0. It will add each number entered to a running total, and when the user enters 0, it will print the total sum of all numbers entered.
Similar Questions
Write a program that repeatedly asks for numbers. When the user enters 0, the program prints the average of all numbers entered (excluding the 0) accurate to two decimal places and exits.
WAP to create an array of 6 integer elements use try and catch block to show exceptionoccured when(i)User enter other than integer throw exception and assign rest value to 0.(ii)user enter other than integer throw exception and assign only that value as 0.
In this exercise you will create a program that computes the average of a collection of values entered by the user. The user will enter 0 as a sentinel value to indicate that no further values will be provided. Your program should display an appropriate error message if the first value entered by the user is 0.Hint: Because the 0 marks the end of the input it should not be included in the average.
You have 3 numbers as user input. WAP in Java to output their values in descending order.
Read a number from the user. Check whether it is zero or non-zero using the lambda function and print the output as either ZERO or NON-ZERO. Sample Input5Sample OutputNON-ZERO
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.