Ask Question
1 November, 15:15

Use a while loop to repeatedly take input from the user and calculate a sum. The user will only be allowed to type in numbers, but remember the input function returns strings (so you will need to convert them with the built-in int function). If the user inputs the value - 999, then the program should stop and print out the sum of all the numbers entered.

+2
Answers (1)
  1. 1 November, 17:07
    0
    Answer and Explanation:

    #take input from user

    n = int (input ("Enter any number: "))

    #sum variable to store sum

    sum=0

    #condition to exit from loop

    while n!=-999:

    #adding entered number in sum variable

    sum=sum+n

    #take input from user

    n = int (input ("Enter any number : "))

    #print the sum

    print ("sum = ", sum)

    output:

    Enter any number: 10

    Enter any number : 100

    Enter any number : - 999

    sum = 110
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Use a while loop to repeatedly take input from the user and calculate a sum. The user will only be allowed to type in numbers, but remember ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers