Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Quizzma Latest Articles

5.2.7 Running Total, Part 2 CodeHS Answers

The most common answer is:

total = 0
number_of_numbers = int(input(“How many numbers would you like to sum? “))
Repeat the code the number of times indicated by the user
for i in range(number_of_numbers):
next = int(input(“Enter a number: “))
total = total + next
print(“Sum: ” + str(total))

To ensure the code runs correctly and adheres to Python syntax, including using standard ASCII quotation marks and the proper use of the print function in Python 3, here’s the revised version of your code:

"""
This program first asks the user how many numbers they want to total. It then
asks them for that many numbers and reports the total of the numbers.
"""

total = 0
number_of_numbers = int(input("How many numbers would you like to sum? "))

# Repeat the code the number of times indicated by the user
for i in range(number_of_numbers):
    next_number = int(input("Enter a number: "))  # 'next' is a built-in function, so using 'next_number' or another variable name is preferable
    total = total + next_number

print("Sum: " + str(total))

This program will:

  • Prompt the user to enter the number of numbers they wish to sum.
  • Use a for loop to repeatedly ask the user to enter a number, adding each entered number to the total.
  • Print the total sum after all the numbers have been entered and summed.

Was this helpful?




Quizzma Team

Quizzma Team

The Quizzma Team is a collective of experienced educators, subject matter experts, and content developers dedicated to providing accurate and high-quality educational resources. With a diverse range of expertise across various subjects, the team collaboratively reviews, creates, and publishes content to aid in learning and self-assessment.
Each piece of content undergoes a rigorous review process to ensure accuracy, relevance, and clarity. The Quizzma Team is committed to fostering a conducive learning environment for individuals and continually strives to provide reliable and valuable educational resources on a wide array of topics. Through collaborative effort and a shared passion for education, the Quizzma Team aims to contribute positively to the broader learning community.

Related Posts