Python:输入三个人的信息(姓名,年龄,薪资,所在城市),存入列表,输出薪资大于15000 元的个人信息(提示:用字典保存个人信息)
时间: 2024-10-22 10:11:31 浏览: 46
在Python中,你可以创建一个列表来存储三个人的个人信息,然后通过遍历这个列表并检查每个人的薪资是否大于15000元来达到你的需求。这里是一个简单的例子:
```python
# 创建一个空列表来存储个人信息
people_info = []
# 循环添加三个人的信息
for i in range(3):
name = input("请输入第{}个人的姓名:".format(i+1))
age = int(input("请输入第{}人的年龄:".format(i+1)))
salary = int(input("请输入第{}人的薪资:".format(i+1)))
city = input("请输入第{}人所在的城市:".format(i+1))
# 使用字典存储个人信息
person_dict = {
"姓名": name,
"年龄": age,
"薪资": salary,
"所在城市": city
}
# 检查薪资并决定是否添加到高薪人员列表
if salary > 15000:
people_info.append(person_dict)
# 输出薪资大于15000元的人员信息
print("\n薪资大于15000元的人员信息如下:")
if people_info:
for person in people_info:
print(person)
else:
print("没有人薪资超过15000元。")
阅读全文
相关推荐
















