# 初学者和简单程序（Python）-无法解决-需要建议

``````def script():

try:
def main():
basePay = float()
payDue = float()
payPerExtraHour = float()
if (hoursWorked > 40.0):
extraHours = float()
extraHoursPay = float()
extraHours = hoursWorked-40.0
basePay = 40 * payPerHour
payPerExtraHour = 1.5 * payPerHour
extraHoursPay = payPerExtraHour*extraHours
payDue = round((basePay + extraHoursPay),2)
else:
payDue = float(hoursWorked*payPerHour)
print('Your gross pay is R'+str(payDue)+'\n')

#repeating script if desired:
def getValidInput():
response = input('Please enter Y(Yes) or N(No)')
if (response == 'Y'):
script()
elif(response == 'N'):
print('\n')
print('Thank you for using Gross Pay Calculator')
else:
condition = True
while (condition==True):
response = str(input('Invalid response received. Please enter Y(Yes) or N(No)'))
if (response == 'Y'):
script()
elif(response == 'N'):
print('\n')
print('Thank you for using Gross Pay Calculator\n')

#prompt to repeat script:
yesOrNo = str(input('Would you like to perform another calculation? (Y/N)\n'))
if(yesOrNo=='Y'):
print('\n')
script()
elif(yesOrNo=='N'):
print('\n')
print('Thank you for using Gross Pay Calculator\n')
else:
response = input('Please enter Y(Yes) or N(No)\n')
if (response == 'Y'):
script()
elif(response == 'N'):
print('\n')
print('Thank you for using Gross Pay Calculator')
else:
getValidInput()

def repeatQuestions():
hoursWorked = input('Enter hours worked: (whole number)\n')
payPerHour = input('Enter pay rate: (hourly rate in Rands(R))\n')
while (hoursWorked != type(float) and payPerHour != type(float)):
try:
hoursWorked = float(input('Enter hours worked: (whole number)\n'))
payPerHour = float(input('Enter pay rate: (hourly rate in Rands(R))\n'))
except:
print('Error, please enter numeric input for each item\n')
if(hoursWorked == type(float) and payPerHour == type(float)):
main()

hoursWorked = float(input('Enter hours worked: (whole number)\n'))
payPerHour = float(input('Enter pay rate: (hourly rate in Rands(R))\n'))

except:
print('Error, please enter numeric input for each item\n')
hoursWorked = input('Enter hours worked: (whole number)\n')
payPerHour = input('Enter pay rate: (hourly rate in Rands(R))\n')
while (hoursWorked != type(float) and payPerHour != type(float)):
hoursWorked = input('Enter hours worked: (whole number)\n')
payPerHour = input('Enter pay rate: (hourly rate in Rands(R))\n')
if (hoursWorked == type(float) and payPerHour == type(float)):
main()

script()
``````