我正在尝试设置一个while
循环,询问用户员工姓名、工作时间和小时工资,直到用户输入“完成”。最终,我将修改代码以计算每周工资并将其写入列表,但一次只做一件事。问题是一旦主while
循环执行一次,它就会停止。不会出错,只是停止。我必须杀死程序才能让它停止。我希望它一次又一次地问这三个问题,直到用户完成。想法?
请注意,这只是一个练习,并不适用于任何现实世界的应用程序。
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