该计划将确定哪个薪水最高,并将其与具有该薪资数字的员工的姓名一起打印出来。
我需要为员工和另一份工资清单制作一份清单。我可以找到最低/最高工资并打印出来,但我不知道如何打印出相应的员工。让这很难的是我们只在第6章,我们只能使用到目前为止学到的东西。所以我们不能使用Python提供的很多内置函数(我们甚至没有覆盖append()方法所以我不得不使用另一种方式添加到列表中。)max和min也是不允许。
amount = int(input("How many employees?: "))
if amount <= 0:
print("You cannot have 0 or less.")
name = []
salary = []
length = len(salary)
mini = 200000
maxi = 0
combined = (name, salary)
for i in range(1, amount + 1):
employee = input("What is the employee's name?: ")
name += [employee]
earned = int(input("How much is the salary? It cannot be less than 0 or over $200,000: "))
while earned <= 0 or earned >= 200000:
earned = int(input("How much is the salary? It cannot be less than 0 or over $200,000: "))
mini = earned
maxi = earned
salary += [earned]
total += earned
if earned < mini:
mini = earned
if earned > maxi:
maxi = earned
答案 0 :(得分:0)
存储索引如下
amount = int(input("How many employees?: "))
if amount <= 0:
print("You cannot have 0 or less.")
name = []
salary = []
length = len(salary)
MAX_SALARY = 200000
mini = MAX_SALARY + 1
maxi = -1
mini_idx = -1
maxi_idx = -1
for i in range(amount):
employee = input("What is the employee's name?: ")
name += [employee]
earned = -1
while earned >= 0 and earned <= MAX_SALARY:
earned = int(input("How much is the salary? It cannot be less than 0 or over $200,000: "))
salary += [earned]
total += earned
if earned < mini:
mini = earned
mini_idx = i
if earned > maxi:
maxi = earned
maxi_idx = i
然后您想要的值由
给出salary[mini_idx]
name[mini_idx]
salary[maxi_idx]
name[maxi_idx]