将用户输入存储到数组中,使用 Python 中的标记值

问题描述 投票:0回答:0

我无法让我的哨兵值正常工作。当用户按0退出时,我想让程序显示所有员工的姓名和薪水,所有薪水的平均值,以及平均值5000范围内的所有员工。我尝试编写和结束函数,但我遇到了同样的问题,所以我删除并插入了 Main() 中的命令。我知道我没有看到或没有做的事情很愚蠢。

#此程序将员工姓名后跟他们的薪水作为输入 #使用标记值,用户可以继续输入姓名和薪水,直到 #按 0 退出。然后它应该打印平均工资,所有员工的姓名和工资 #employees 以及平均水平 5,000 以内的人员的姓名和薪水

import statistics

names = []
salaries = []
e = None




def Main():
    e = None
    count = 1
    while e != 0:
        e = input(f"Enter Employee {count} Name      (press 0 to quit):  ")
        s = float(input(f"Enter Employee {count} salary (in hundreds)      (press 0 to quit):  "))
        L = [e, s]
        count = count+1
        names.append(L)
        salaries.append(L)
    print(names)
    print(statistics.mean(names))


Main()
python arrays statistics user-input
© www.soinside.com 2019 - 2024. All rights reserved.