我正在尝试创建一个程序,其中有 3 个列表,这些列表将根据列表中的索引位置打印出姓名、工资和总工资。
每个变量的长度不能只是 6,因此它应该适应任何给定的输入(姓名/工资/小时列表可以根据需要而定)。忽略数据验证/格式化,因为我们假设用户将始终正确输入所有变量的信息。
例如,我希望我想要的输出是(参见代码中 3 个变量列表中的索引 0):
Sanchez worked 42.0 hours at $10.00 per hour, and earned $420.00
$420.00 -> (10.00*42.0)
目前这里是我的代码:
name = ['Sanchez', 'Ruiz', 'Weiss', 'Choi', 'Miller', 'Barnes']
wage = ['10.0', '18', '14.80', '15', '18', '15']
hours = [42.0, 41.5, 38.0, 21.5, 21.5, 22.5]
i = 0
for y in name:
payOut = float(wage[i]) * float(hours[i])
product = (name[i], wage[i], payOut)
i += 1
print(product)
empName = input("gimmie name: ") #no data validation neeeded
def target(i,empName):
for x in i:
if x == str(empName):
empName = x #should return index of the empName
'''^^^ this is currently incorrect too as i believe it should return
the index location of the name, which I will use to print out the
final statement based upon the location of each respective variable
list. (not sure if this works)'''
target(name,empName)
倚天杖
郎朗坤
qq_遁去的一_1
相关分类