Good evening,
I was wondering how I could set up a loop for the following code that will exit the loop when the person types done. Would the while command work to do that?

def hours():
    hours = input("How many hours did they work?: ")
    return hours
 
def payrate():
    payrate = input("How much is their payrate?: ")
    return payrate
 
def calchours(pr, h):
    if h > 40:
        rh = 40
        oh = h - 40
        if h > 60:
            print "Can't exceed 60 hours in a week!"
    else:
        rh = h
        oh = 0
    
def main():
    hrs = hours()
    pyr = payrate()
    calchours (pyr, hrs)
 
main()

this is my code:

def hours():
    hours = input("How many hours did they work?: ")
    return hours
 
def payrate():
    payrate = input("How much is their payrate?: ")
    return payrate
 
def calchours(pr, h):
    if h > 40:
        rh = 40
        oh = h - 40
        if h > 60:
            print "Can't exceed 60 hours in a week!"
    else:
        rh = h
        oh = 0
    
def main():
    a ="True"
    while a is "True":
        hrs = hours()
        pyr = payrate()
        calchours (pyr, hrs)
        a = raw_input("is that all( False for yes, True for no)")
 
main()

ive tested it a bit, but ive noticed theres nothing that calculates the pay

Hi, you can use this code instead of going for while loop.

def hours():
hours = input("How many hours did they work?: ")
return hours

def payrate():
payrate = input("How much is their payrate?: ")
return payrate

def calchours(pr, h):
if h > 40:
rh = 40
oh = h - 40
if h > 60:
print "Can't exceed 60 hours in a week!"
else:
rh = h
oh = 0

def main():
hrs = hours()
pyr = payrate()
calchours (pyr, hrs)
a = raw_input("is that all( False for yes, True for no)")
if a == 'yes':
main()
elif a =='no':
quit
main()

This "is" operator is meant to be used to test for the same object, not equality. Try this on your computer
a=257
print a is 257
<prints "False">
So it can give you unexpected results. You want to use:

a = True
    while a :
        a = False   ## (to exit)
##
##--- or
    a ="True"
    while a == "True":
This article has been dead for over six months. Start a new discussion instead.