Ask Question
28 October, 22: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.

+1
Answers (1)
  1. 28 October, 22:44
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers