Python如果elif编写代码来创建paych

2024-05-13 12:28:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用Python编码在用户输入所述小时数时创建工资支票。每周工作25.9美元的标准工资是每小时25.9美元。任何超过40小时的活动将获得奖金的150%(即9.25的150%)。我还应该能够输入分数形式的小时数,并能够打印工资支票作为输出(其中说明工作小时数、每小时工资、收到的奖金(如果有)和总工资)

到目前为止,我已经能够成功地使用if-else语句来获得最终结果,但是我不知道如何在输出中接受分数并打印整个工资单。我对Python相当陌生,非常喜欢它。有人能帮我即兴编写代码,帮我做分数和打印整个工资单吗?在

这是我目前为止的代码。在

hours = int(input('Please enter the number of hours...'))

if hours <= 40:
    hourlyWage = hours*(9.25)

elif hours > 40:
    hourlyWage = hours*(9.25*1.5)

print('Your salary is ${0}'.format(hourlyWage))

谢谢你,我们非常感谢你的帮助!在


Tags: 代码用户编码if工资单else分数形式
3条回答
hours = float(input('Please enter the number of hours...'))
hourlyWage = hours*(9.25)
hours = hours - 40
if hours > 0:
    hourlyWage = hourlyWage + (hours*(9.25*1.5))

print('Your salary is ${0}'.format(hourlyWage))
hours = float(input('Please enter the number of hours...'))   
pay = hours * 9.25 + max(hours-40,0)* (9.25*1.5-9.25)
print('Your salary is ${0}'.format(pay))
hours = int(input('Please enter the number of hours...'))

hourlyWage = 9.25
bonus = 0.5
bonusThreshold = 40
bonusHours = max(0, hours - bonusThreshold)
regularSalary = hourlyWage * hours
bonusSalary = bonusHours * hourlyWage * bonus
totalSalary = regularSalary + bonusSalary

print('Worked: {0} hours.'.format(hours))
print('Pay per hour: ${0}.'.format(hourlyWage))
print('Bonus received: ${0}'.format(bonusSalary))
print('Total salary: ${0}'.format(totalSalary))

相关问题 更多 >