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

  • SEARCH
  • Home
  • 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 9163273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:24:27+00:00 2026-06-17T14:24:27+00:00

Purpose is to put diff ages in, if -1 is entered then the program

  • 0

Purpose is to put diff ages in, if -1 is entered then the program stops, my totaling statement is wrong. Will Someone please help me fix it.

Totalage = 0

age = 0

print "Enter you Family member's ages!"

age = raw_input ("Enter an age ")

while age != -1:
    age = input("Enter an age ")
    Totalage = Totalage + age

print Totalage
  • 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-17T14:24:28+00:00Added an answer on June 17, 2026 at 2:24 pm

    There are two problems with your code

    1. You are skipping your first input, and you are not adding it to your total
    2. You are adding the last terminator input -1 to your Total.

    Just Change the order of the statements in your while loop

    age = int(raw_input ("Enter an age "))
    while age != -1:    
        Totalage = Totalage + age
        age = int(input("Enter an age "))
    

    Also note, raw_input, in general returns a string, which needs to be converted to int before you may want to calculate on it.


    Itertools Provide some wonderful tools, and for fun, I tried coding the above while loop with itertools.takewhile

    >>> from itertools import count, takewhile
    >>> sum(takewhile(lambda x: x != -1,
              (int(raw_input("Enter an age ")) for e in count())))
    Enter an age 20
    Enter an age 30
    Enter an age 40
    Enter an age 50
    Enter an age -1
    140
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a new programmer trying to understand someone else's code. The program's purpose is
When i run the program and select premium it runs it put then it
I am trying to put a general purpose function together that will sanitize input
Would you put the annotation in implementation class methods? Does it serve any purpose?
I have a program whose only purpose is to drive a java.awt.Robot in an
How do you load an image from a URL and then put it into
We consider to put one of our assemblies in the GAC for the purpose
I know I can put HTML and JavaScript into a separate projects and then
I'm trying to put an array in to getElementById for a loop purpose. It
When I put an instance of a custom class into Session and then pull

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.