Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.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 - Fatal编程技术网

Python 我在这一点上卡住了

Python 我在这一点上卡住了,python,Python,因此,我试图完成我的代码,这是要求用户的姓名,每小时工资和工作时间这一周,该计划必须打印的名称,每小时工资和多少,他们赚了这一周。星期六的工资是一倍半,星期天的工资是两倍。 现在我想到了这个,但是当我运行代码时,它说 pay = (days[0] + days[1] + days[2] + days[3] + days[4] + (days[5] * 1.5) + (days[6] * 2)) * wage TypeError: can't multiply sequence by non-in

因此,我试图完成我的代码,这是要求用户的姓名,每小时工资和工作时间这一周,该计划必须打印的名称,每小时工资和多少,他们赚了这一周。星期六的工资是一倍半,星期天的工资是两倍。 现在我想到了这个,但是当我运行代码时,它说

pay = (days[0] + days[1] + days[2] + days[3] + days[4] + (days[5] * 1.5) + (days[6] * 2)) * wage
TypeError: can't multiply sequence by non-int of type 'float'
这是我的代码:

days = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
hours = []

name = input("Enter employee's name: ")
wage = float(input("Enter your hourly rate: "))

for x in range(7):
    daily = float(input("Enter the number of hours you worked on " + days[x] +': '))
    hours.append(daily)

pay = (days[0] + days[1] + days[2] + days[3] + days[4] + (days[5] * 1.5) + (days[6] * 2)) * wage

print("Employee name: ",name)
print("Hourly rate: ",wage)
print("Total earned this week: ",pay)

顺便说一句,这不是我的家庭作业,只是我在网上看到的一个问题

days
是字符串列表<代码>天[5]是该列表中的第六个字符串(
“星期六”

在Python中,可以将字符串与整数“相乘”

>>> "Saturday" * 3
'SaturdaySaturdaySaturday'
该数字不能是浮点数:

>>> "Saturday" * 1.5
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    "Saturday" * 1.5
TypeError: can't multiply sequence by non-int of type 'float'
>>> 
>“星期六”*1.5
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
“星期六”*1.5
TypeError:无法将序列与“float”类型的非int相乘
>>> 

您可能打算使用
小时
而不是

只要将您的
支付
声明更改为:

工资=(小时[0]+小时[1]+小时[2]+小时[3]+小时[4]+(小时[5]*1.5)+(小时[6]*2))*工资

我认为你需要使用“小时”列表而不是天数。您的“天”列表是所有天的列表,小时是存储所有日工资的位置,因此它显示typeerror,表示您不能用字符串乘以float

在此代码段中将天替换为小时 工资=(小时[0]+小时[1]+小时[2]+小时[3]+小时[4]+(小时[5]*1.5)+(小时[6]*2])*工资


谢谢

问题在于天是一周中几天的列表。我认为您希望在计算
工资时使用
小时
而不是