Question

Python 3.6 "While Loops" Write a program that adds up a series of numbers entered by...

Python 3.6 "While Loops"

Write a program that adds up a series of numbers entered by the user. The user should enter each number at the command prompt. The user will indicate that he or she is finished entering the number by entering the number 0.  

Example

This program will sum a series of numbers.
Enter the next number (enter 0 when finished)
> 5
Enter the next number (enter 0 when finished)
> 2
Enter the next number (enter 0 when finished)
> 10
Enter the next number (enter 0 when finished)
> 0
The sum of your numbers is 17.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

print("This program will sum a series of numbers.")
total = 0
n = int(input("Enter the next number (enter 0 when finished): "))
while n != 0:
total = total + n
n = int(input("Enter the next number (enter 0 when finished): "))
print("The sum of your numbers is ",total)

Output:

This program will sum a series of numbers.
Enter the next number (enter 0 when finished)
> 5
Enter the next number (enter 0 when finished)
> 2
Enter the next number (enter 0 when finished)
> 10
Enter the next number (enter 0 when finished)
> 0
The sum of your numbers is 17.

Execute I Embed main.py STOIN . Result Spython3 main.Py This progran wi11 sun a series of numbers Enter the next number (ente

Add a comment
Know the answer?
Add Answer to:
Python 3.6 "While Loops" Write a program that adds up a series of numbers entered by...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 4-6 Please. Python 3.6. def main(). entered by a user. Write a program that finds...

    Question 4-6 Please. Python 3.6. def main(). entered by a user. Write a program that finds the sum and average of a series of numbers he program should first prompt the user to enter total numbers of numbers are to be summed and averaged. It should then as for input for each of the numbers, add them, and print the total of the numbers and their average 2. Write a progra m that finds the area of a circle. The...

  • Write a program that receives a series of numbers from the user and allows the user...

    Write a program that receives a series of numbers from the user and allows the user to press the enter key to indicate that he or she is finished providing inputs. After the user presses the enter key, the program should print the sum of the numbers and their average.   >>> totalSum =0 >>> count=0 >>> while True:    number=input("Enter a number or press enter to quit:")    if number =="":        break    totalSum += float(number)    count+=1...

  • Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program...

    Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program will calculate and display the total of all numbers up to a specific number (entered by the user). Only positive numbers are allowed. Part B: User-controlled loop Part A Input Validation loop Part A: Summation loop Examples: When 5 is entered the program will calculate the total as 1+2+...+5 and display 15. When 2 is enterered the program will calculate the total as 1+2...

  • Write a program named ClassifyScores that classifies a series of scores entered by the user into...

    Write a program named ClassifyScores that classifies a series of scores entered by the user into ranges (0-9, 10-19, and so forth). The scores will be numbers between 0 and 100. Design and implement a program to prompt the user to enter each score separately. If the score is within the correct range, then increment the appropriate range If the score entered is greater than 100, display an error message, ignore the incorrect score, and prompt for the user to...

  • need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that...

    need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that first prompts the user for an upper limit: Enter the number of entries: 5 € (user enters 5) After the user enters a number, the program should prompt the user to enter that many numbers. For example, if the user enters 5, then the program will ask the user to enter 5 values. Use a do-while loop to add the numbers. o With each...

  • IN PYTHON Write a function that does not receive parameters but the user must enter numbers...

    IN PYTHON Write a function that does not receive parameters but the user must enter numbers until they give him a 0. While the user does not give him a 0, the program must show how many numbers were entered, the sum of these numbers and the average (not counting the 0) example: 16 4 42 8 23 15 0 output: numbres = 6 sum = 108 average = 18.0

  • Objectives: Learn how to use the C++ while and for loops. Instructions: A perfect number is...

    Objectives: Learn how to use the C++ while and for loops. Instructions: A perfect number is a positive integer greater than 1 that is equal to the sum of the positive integer numbers, including 1 but not including itself, that evenly divide into it. First, you should prompt the user for a number. Next, you should indicate if the number is a perfect number or not. Finally, you should list the numbers that evenly divide into the number entered and...

  • Write a Python program (special_sum.py) that calculate a special sum of 4 numbers, all int. The...

    Write a Python program (special_sum.py) that calculate a special sum of 4 numbers, all int. The rule for this special sum is as follow: If one of the entered numbers is 17, then it does not count towards the sum and the numbers entered after it do not count. For full credit, you must use function. Your function should have 4 int as parameters, and returns the special sum (as an int). Call this function specialsum and use main program:...

  • I have to write a program in java which uses while loops. 1.prompt the user to...

    I have to write a program in java which uses while loops. 1.prompt the user to input two intergers: firstnum ans second numnumber. (first number must be smaller that the second number). 2. Output all the even numbers between first number and second number inclusive. 3. Output the sum of all the even number between first number and second number inclusive. 4 Output all the odd numbers between first number and second number inclusive. 5. Output the sum of all...

  • Please do this in C++ using only for loops, while loops, and do while loops. No...

    Please do this in C++ using only for loops, while loops, and do while loops. No arrays. Use for loop, while loop, and do while loops to generate a table of decimal numbers, as well as the binary, octal, and hexadecimal equivalents of the decimal numbers in the range 1-256 Note: See Appendix for number systems The program should print the results to the Console without using any string formats Design Details: The Main program should prompt the user for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT