我正在研究employees中的pay raise,特别是ids.假设我的公司有5名员工.我在employee_id_list中展示了它们.我想让python从我这里获取信息,包括employees人中的ids人,我想提高工资,以及他们的salary人.然后,我从这些输入中创建dictionary.现在我想迭代employee_id_list,使其与input ids匹配.如果匹配的话,我想分别取value of keysalary,并提高工资.但我犯了个错误.

employee_id_list = [27, 25, 98, 78, 66]
employee_dict = dict()
while True:
    x = input("Enter an key to continue and 'r' for result: ").lower()
    if x== 'r':
        break
    try:
        employee_id = int(input("Enter key the Employee id: ")) 
        salary = int(input(f"Enter the {employee_id}'s salary: "))
        employee_dict[employee_id] = salary
    except ValueError:
        print("Please Enter the Integers!")
        continue 
print(employee_dict)
for e_ids in employee_id_list:
    for key, value in employee_dict.items():
        if e_ids in employee_dict[key] :
            employee_dict[value] = 0.8*value + value
print(employee_dict)

我犯了这个错误

TypeError: argument of type 'int' is not iterable

推荐答案

将@Konny和@Sunderam的正确 idea 放在一起,并添加我自己的更改以判断if语句,答案是:

employee_id_list = [27, 25, 98, 78, 66]
    employee_dict = dict()

    while True:
        x = input("Enter an key to continue and 'r' for result: ").lower()
        if x== 'r':
            break
        try:
            employee_id = int(input("Enter key the Employee id: "))
            salary = int(input(f"Enter the {employee_id}'s salary: "))
            employee_dict[employee_id] = salary
        except ValueError:
            print("Please Enter the Integers!")
            continue

    print(employee_dict)
    for e_ids in employee_id_list:
        for key, value in employee_dict.items():
            if e_ids == key:    # This is my contribution
                employee_dict[key] = 1.8*value
    print(employee_dict)

Python相关问答推荐

在Windows上启动新Python项目的正确步骤顺序

过滤绕轴旋转的螺旋桨

使用matplotlib pcolormesh,如何停止从一行绘制的磁贴连接到上下行?

如何将桌子刮成带有Se的筷子/要求/Beautiful Soup ?

使用多个性能指标执行循环特征消除

按照行主要蛇扫描顺序对点列表进行排序

如何在图片中找到这个化学测试条?OpenCV精明边缘检测不会绘制边界框

Python多处理:当我在一个巨大的pandas数据框架上启动许多进程时,程序就会陷入困境

什么相当于pytorch中的numpy累积ufunc

如何列举Pandigital Prime Set

pyscript中的压痕问题

为什么NumPy的向量化计算在将向量存储为类属性时较慢?'

为一个组的每个子组绘制,

网格基于1.Y轴与2.x轴显示在matplotlib中

计算空值

Pandas—堆栈多索引头,但不包括第一列

使用类型提示进行类型转换

Django Table—如果项目是唯一的,则单行

freq = inject在pandas中做了什么?''它与freq = D有什么不同?''

jsonschema日期格式