Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

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

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8248709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:17:05+00:00 2026-06-07T23:17:05+00:00

Keep in mind that I am still very new to python coding as I

  • 0

Keep in mind that I am still very new to python coding as I am only just into chapter 5 of my python coding class. Keeping that in mind, I am attempting to create a sum calculator using a “while loop” to continue until the user enters a negative number instead of a positive number.

In case I am not entirely clear in my description of my question I will post the exact homework problem here:

Chapter 5, page 200, #8
Sum of Numbers

Write a program with a while loop that asks the user to enter a series of positive numbers. The user should enter a negative number to signal the end of the series. After all the positive numbers have been entered, the program should display their sum.

Now for the code that I have written so far:

def main():
    number = float(input('Please enter in a positive number: '))
    while number > 0:
        positiveNumber()
    while number < 0:
        calculateTotal()
        printTotal()

def positiveNumber():
    number = float(input('If you are finished please enter a negative number.' + \ 'Otherwise, enter another positive number: '))
    while number > 0:
        positiveNumber()
    while number < 0:
        calculateTotal()
        printTotal()

def calculateTotal():
    total = 0 + number

def printTotal():
    print('The sum of your numbers is: ', total)

main()
  • In line 11, I have the “+ \” sign there because I wanted to make an enter space there in order to have a cleaner looking text, but that does not seem to work.

I apologize if this question seems “nooby” but I need help making a cleaner/working sum calculator. I would greatly appreciate it if someone can take a look at this code and hopefully help me improve it. Thank you!

Final Edit:

Thank you all for the informative answers! I learned alot (for a “newbie” =]). I used Talon876’s answer for my calculator. Thanks again everyone!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:17:07+00:00Added an answer on June 7, 2026 at 11:17 pm

    If you want a single string to be printed on multiple lines, put a \n in the string.
    For example,

    print "This is on the first line\nThis is on the second line"
    

    would output

    This is on the first line
    This is on the second line
    

    It looks like you’re mixing a while loop with recursion (calling a method from within itself). I would suggest using a single while loop and an input variable to check for the breaking condition (the input is < 0)

    It would look something like this:

    sum = 0
    number = float(input('Please enter in a positive number: '))
    while number > 0:
        sum = sum + number
        number = float(input('If you are finished please enter a negative number.' + \ 'Otherwise, enter another positive number: ')) #fix this line using the information from the first part of the answer
    

    This will loop until the user inputs a negative number, or 0. If you want to accept 0 as a positive number, change the while condition to number > -1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to programming in general so please keep that in mind when
I'm a complete n00b with MacRuby and Cocoa, so keep that in mind when
I'm using VB.net so keep that in mind. I'm trying to create a program
(Keep in mind this is on OSX Snow Leopard) I don't know how to
keep in mind I normally use pure as3 and FlashDevelop :) I am really
What are some tips one can keep in mind to speed up jSoup? I
What are some best practices to keep in mind when developing a script program
Keep running into When using the multi-mapping APIs ensure you set the splitOn param
Keep getting this error after inserting a subdatasheet into a query and trying to
Keep going around circles, but I am still unclear about this. Have a feeling

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.