首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Python中并行数组打印职员和工资

在Python中并行数组打印职员和工资
EN

Stack Overflow用户
提问于 2013-04-05 00:50:33
回答 1查看 1.5K关注 0票数 0

该程序将确定最高的工资,并将其与拥有该工资数字的员工的姓名一起打印出来。

我需要做一份员工清单和另一份薪水清单。我可以找到最低/最高工资并将其打印出来,但我不知道如何打印相应的员工。让这件事变得困难的是,我们只是在第6章,我们只能使用到目前为止所学到的知识。所以我们不能使用Python提供的很多内置函数(我们甚至还没有介绍append()方法,所以我不得不使用另一种方法来添加到列表中。)也不允许使用max和min。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-05 01:06:54

按如下方式存储索引

代码语言:javascript
复制
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

然后,您想要的值将由

代码语言:javascript
复制
salary[mini_idx]
name[mini_idx]
salary[maxi_idx]
name[maxi_idx]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15817122

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档