所以我不得不将我的伪代码转换为python,但是我的输出并不是应该出现的。
我输入40小时的工作和20个工资率,但总工资没有出来(总工资应该是800)。任何人都可以告诉我什么是错的?
BASE_HOURS = 40
OT_MULTIPLIER = 1.5
def main():
hours_worked = int(input('Enter the number of hours worked: '))
pay_rate = int(input('Enter the hourly pay rate: '))
if hours_worked > BASE_HOURS:
calc_pay_with_OT(hours_worked, pay_rate)
else:
calc_regular_pay(hours_worked, pay_rate)
def calc_pay_with_OT(hours, pay_rate):
overtime_hours = hours_worked - BASE_HOURS
overtime_pay = overtime_hours * pay_rate + OT_MULTIPLIER
gross_pay = BASE_HOURS * pay_rate + overtime_pay
print('The gross pay is $ '), gross_pay
def calc_regular_pay(hours, pay_rate):
gross_pay = hours * pay_rate
print('The gross pay is $ '), gross_pay
main()
答案 0 :(得分:0)
print语句应该是print('The gross pay is $'+str(gross_pay))
str()
函数将整数gross_pay转换为字符串,以便它可以在print函数中连接。