Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
输入Python程序的工作小时数_Python_Python 3.x - Fatal编程技术网

输入Python程序的工作小时数

输入Python程序的工作小时数,python,python-3.x,Python,Python 3.x,问题是: 编写一个程序,要求用户输入一个整数'n',该整数 将是用户一周内工作的总小时数 计算并打印用户在使用过程中赚取的总金额 那周。如果用户输入的数字小于0或大于 168(n168)则程序应打印无效 假设前40小时的小时费率为每小时8美元 41到50之间额外工作小时的小时费率(如果工作小时数168,则为41 不正确 指 这是写这句话的正确方法: if hours < 0 or hours > 168: 如果小时数168: 此外,以下内容也不正确: elif hours (&

问题是:

编写一个程序,要求用户输入一个整数'n',该整数 将是用户一周内工作的总小时数 计算并打印用户在使用过程中赚取的总金额 那周。如果用户输入的数字小于0或大于 168(n<0或n>168)则程序应打印无效

假设前40小时的小时费率为每小时8美元

41到50之间额外工作小时的小时费率(如果工作小时数<0或>168,则为41<代码> 不正确 指

这是写这句话的正确方法:

if hours < 0 or hours > 168:
如果小时数<0或小时数>168:
此外,以下内容也不正确:

elif hours (<=41 or <=50)
elif小时数(代码:

产出2:

how many hours did you work this week? 67

YOU MADE 580 DOLLARS THIS WEEK

这还不算Python代码。你需要一个结构化的教程,例如,作为一个新的贡献者,请参阅精彩的解释。我建议你也用正确的完整代码总结OP的答案。这样,他们就可以看到它是如何组合在一起的。谢谢你们,我几天前才开始编写代码,所以在理解之前,我必须学习很多这一切之后的逻辑。
elif hours (<=41 or <=50)
elif hours <= 50:
import sys

hours = int(input("how many hours did you work this week? "))

if hours  < 0 or hours > 168:
    print("invalid")
    #here i used sys.exit so that it can exit after printing invalid
    sys.exit()
elif hours  <= 40 and hours > 0:
    a = hours
    b = 0
    c = 0 
elif hours>40 and hours <= 50:
    a = 40
    b = (hours - a)
    c = 0
elif hours > 50:
    a = 40
    b = 10
    c = hours - (a+b)

rate = (a*8)+(b*9)+(c*10)
print("\n\nYOU MADE {} DOLLARS THIS WEEK".format(rate))
how many hours did you work this week? 34

YOU MADE 272 DOLLARS THIS WEEK
how many hours did you work this week? 67

YOU MADE 580 DOLLARS THIS WEEK