python 3.x - How do i make the program exit by entering 0 -


# abc inc., gross pay calculator! # enter employee's name or 0 quit : nathan # enter hours worked : 35 # enter employee's pay rate : 10.00 # employee name : nathan # gross pay: 350.0 # enter next employee's name or 0 quit : toby # enter hours worked : 45 # enter employee's pay rate : 10 # employee name : toby # gross pay : 475.0 # (overtime pay : 75.0 ) # enter next employee's name or 0 quit : 0 # exiting program... 

how make input 0 print "exiting program" exit?

print('abc inc., gross pay calculator!') name = input("enter employee's name or 0 quit:") hours = float(input("enter hours worked:")) payrate = float(input("enter employee's pay rate:")) print("employee name:", name) grosspay = hours * payrate print("gross pay:", grosspay) if hours > 40: print("(overtime pay:", (hours - 40) * payrate * 1.5) while name!=0:     name = input("enter next employee's name or 0 quit:")     hours = float(input("enter hours worked:"))     payrate = float(input("enter employee's pay rate:"))     print("employee name:", name)     grosspay = hours * payrate     print("gross pay:", grosspay)     if hours > 40:         print("(overtime pay:", (hours - 40) * payrate*1.5) else:     print ('exiting program...') 

do not repeat code that. instead use while true: , conditional break appropriate place. standard 'loop-and-a-half' idiom in python.

print('abc inc., gross pay calculator!') while true:     name = input("enter employee's name or 0 quit:")     if name == '0':         print ('exiting program...')         break     hours = float(input("enter hours worked:"))     payrate = float(input("enter employee's pay rate:"))     print("employee name:", name)     grosspay = hours * payrate     print("gross pay:", grosspay)     if hours > 40:         print("(overtime pay:", (hours - 40) * payrate * 1.5) 

i replace '0' in prompt 'nothing' , make test if not name:, minor issue.


Comments

Popular posts from this blog

mongodb - How to keep track of users making Stripe Payments -

javascript - Fire on return from form "Submit" -

javascript - Thinglink image not visible until browser resize -