<p>在payCalc函数中,您需要编写<code>othours = hours[0]</code>而不是<code>othours = hours[1]</code>来获得小时数(因为现在它给出了数字的真值或假值)</p>
<pre><code>def data():
wage = float(input('What is your payrate? '))
while wage < 7 or wage > 50:
print('Invalid input. Wage must be between $7.00 and $51.00. Please try again.')
rate = float(input('What is your payrate? '))
hours = float(input('How many hours were worked? '))
while hours < 8 or hours > 86:
print('Invalid input. Hours worked must be between 8 and 86. Please try again.')
hours = float(input('How many hours were worked? '))
return hours, wage
def timeCalc(hours):
if hours <= 40:
return[hours, False]
else:
othour = hours - 40
return[othour, True]
def payCalc(hours, wage):
if hours[1]:
othours = hours[0] # Change Code here
otpay = othours * (wage * 1.5)
regularpay = 40 * wage
return otpay, regularpay, othours
else:
return None
def main():
hours, wage = data()
if payCalc(timeCalc(hours), wage) == None:
print(' Payroll Information ')
print('Pay Rate: $%.2f' % wage)
print('Regular Hours: %.0f' % hours)
print('Overtime Hours: 0')
print('Regular pay: $%.2f' % (hours * wage))
print('Overtime pay: $0.00')
print('')
print('Total pay: $%.2f' % (hours * wage))
else:
otpay, regularpay, othours = payCalc(timeCalc(hours), wage,)
print(' Payroll Information ')
print('Pay Rate: $%.2f' % wage)
print('Regular Hours: %.0f' % (hours - othours))
print('Overtime Hours: %.0f' % othours)
print('Regular pay: $%.2f' % (hours * wage))
print('Overtime pay: $%.2f' % otpay)
print('Total pay: $%.2f' % (regularpay + otpay))
main()
</code></pre>
<p>这是输出</p>
<pre><code>What is your payrate? 50
How many hours were worked? 50
Payroll Information
Pay Rate: $50.00
Regular Hours: 40
Overtime Hours: 10
Regular pay: $2500.00
Overtime pay: $750.00
Total pay: $2750.00
</code></pre>
<p>希望这能奏效!!你知道吗</p>