if语句

**3.1 Conditional Execution** Problem
Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay the hourly rate for the hours up to 40 and 1.5 times the hourly rate for all hours worked above 40 hours. Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75). You should use input to read a string and float() to convert the string to a number. Do not worry about error checking the user input - assume the user types numbers properly.
根据工作时间和每小时工资计算总工资。当工作时长小于40小时,每小时工资为10.50;对于超过部分给予正常工作的1.5倍工资。此处假定45小时。 必须使用input()和float()函数。
Desired Output
498.75
Code
# This first line is provided for you
hrs_str = input("Enter Hours:")
rat_str = input("Enter Ratio:")

hrs_num = float(hrs_str)
rat_num = float(rat_str)

if hrs_num > 40 ://一定要用:  且本code要用if
print(40*rat_num +(hrs_num-40)*rat_num *1.5)
else://else后也要加 :
print(hrs_num*rat_num )
————————————————
版权声明:本文为CSDN博主「yanqs_whu」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u012348774/article/details/78106407

posted @ 2022-09-04 19:25  continentliang  阅读(12)  评论(0编辑  收藏  举报