Ask Question
1 September, 09:31

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 September, 12:13
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers