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 718901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:34:50+00:00 2026-05-14T05:34:50+00:00

I’m trying to set up a while loop that will ask the user for

  • 0

I’m trying to set up a while loop that will ask the user for the employee name, hours worked and hourly wage until the user enters ‘DONE’. Eventually I’ll modify the code to calculate the weekly pay and write it to a list, but one thing at a time. The problem is once the main while loop executes once, it just stops. Doesn’t error out but just stops. I have to kill the program to get it to stop. I want it to ask the three questions again and again until the user is finished. Thoughts?

Please note that this is just an exercise and not meant for any real world application.

def getName(): 
    """Asks for the employee's full name"""
    firstName=raw_input("\nWhat is your first name? ")
    lastName=raw_input("\nWhat is your last name? ")
    fullName=firstName.title() + " " + lastName.title()
    return fullName

def getHours():
    """Asks for the number of hours the employee worked"""
    hoursWorked=0 
    while int(hoursWorked)<1 or int(hoursWorked) > 60: 
        hoursWorked=raw_input("\nHow many hours did the employee work: ")
        if int(hoursWorked)<1 or int(hoursWorked) > 60:
            print "Please enter an integer between 1 and 60."
        else:
            return hoursWorked

def getWage():
    """Asks for the employee's hourly wage"""
    wage=0 
    while float(wage)<6.00 or float(wage)>20.00: 
        wage=raw_input("\nWhat is the employee's hourly wage: ")
        if float(wage)<6.00 or float(wage)>20.00:
            print ("Please enter an hourly wage between $6.00 and $20.00")
        else:
            return wage


##sentry variables
employeeName=""
employeeHours=0
employeeWage=0
booleanDone=False

#Enter employee info
print "Please enter payroll information for an employee or enter 'DONE' to quit."

while booleanDone==False:
    while employeeName=="":
        employeeName=getName() 
        if employeeName.lower()=="done":
            booleanDone=True
            break
        print "The employee's name is", employeeName

    while employeeHours==0:
        employeeHours=getHours() 
        if employeeHours.lower()=="done":
            booleanDone=True
            break
        print employeeName, "worked", employeeHours, "this week."

    while employeeWage==0:
        employeeWage=getWage() 
        if employeeWage.lower()=="done":
            booleanDone=True
            break
        print employeeName + "'s hourly wage is $" + employeeWage
  • 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-05-14T05:34:51+00:00Added an answer on May 14, 2026 at 5:34 am

    The problem is that after the first loop, employeeName and the other variables will already have values, so your inner while loops will be skipped. This leads to the outer loop repeating infinitely without doing anything.

    I would just remove the inner while loops: you don’t really need them, because you already do validation inside getHours and the other functions. Another option is to reset the variable values at the start of the outer while loop.

    Some more things to improve (not related to this error):

    • In getHours and getWage, you can just use while True instead of the condition you have now. If the condition is false, you would have returned from the function already anyway.

    • You need to catch ValueError in getHours and getWage, in case non-numeric data was entered.

    • instead of booleanDone==False, use not booleanDone. Though if you remove the inner loops as I suggested, you don’t even need this boolean: Just break out of the loop when needed.

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

Sidebar

Ask A Question

Stats

  • Questions 383k
  • Answers 383k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer strtok modifies the input string line. char *line = "LINE… May 14, 2026 at 10:45 pm
  • Editorial Team
    Editorial Team added an answer I'm not 100% sure of your question, but I think… May 14, 2026 at 10:45 pm
  • Editorial Team
    Editorial Team added an answer Your "callback" is not a callback, but a rule. What… May 14, 2026 at 10:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.