#用你能想到的最少的代码生成一个包含100个key的字典,每个value的值不能一样
# dict_create = {}.fromkeys([i for i in range(1,101)],1)
# value = 1
# while value < 101:
# dict_create[value]=value
# value +=value
# print(dict_create)
dict_100 = {}
for i in range(1,101):
dict_100[i]=i
print(dict_100)
"""
{‘k0’: 0, ‘k1’: 1, ‘k2’: 2, ‘k3’: 3, ‘k4’: 4, ‘k5’: 5, ‘k6’: 6, ‘k7’: 7, ‘k8’: 8, ‘k9’: 9}
请把这个dict中value大于5的值key打印出来。
"""
dict_test = {'k0':0,'k1':1,'k2':2,'k3':3,'k4':4,'k5':5,'k6':6,'k7':7,'k8':8,'k9':9}
# for key in dict_test:
# if dict_test[key] > 5:
# print(key)
"把题2中value是偶数的统一改成-1"
# for key in dict_test:
# if dict_test[key] % 2 == 0:
# dict_test[key] = -1
# print(dict_test)
"""
请设计一个dict, 存储你们公司每个人的信息,
信息包含至少姓名、年龄、电话、职位、工资
并提供一个简单的查找接口,用户按你的要求输入要查找的人,你的程序把查到的信息打印出来
"""
"""
dict = {
[]
}
"""
dict_xinxi = {
"id1":[{'name':'山山','age':25,'iphone':'131111111','zhiwei':'员工','gongzi':'4000'}],
"id2":[{'name':'小崔','age':24,'iphone':'132222222','zhiwei':'经理','gongzi':'8000'}],
"id3":[{'name':'黑姑娘','age':20,'iphone':'13333333','zhiwei':'总经理','gongzi':'12000'}],
}
dict_xinxi2 = {
"山山":[{'age':25,'iphone':'131111111','zhiwei':'员工','gongzi':'4000'}],
"小崔":[{'age':24,'iphone':'132222222','zhiwei':'经理','gongzi':'8000'}],
"黑姑娘":[{'age':20,'iphone':'13333333','zhiwei':'总经理','gongzi':'12000'}],
}
def select_information(select_value):
if dict_xinxi2.get(select_value):
age = dict_xinxi2[select_value][0]['age']
iphone = dict_xinxi2[select_value][0]['iphone']
zhiwei = dict_xinxi2[select_value][0]['zhiwei']
gongzi = dict_xinxi2[select_value][0]['gongzi']
print(
"""
员工姓名:{name}
-----------------------
个人信息
-----------------------
年龄:{age}
手机号:{iphone}
职位:{zhiwei}
工资:{gongzi}
""".format(name=select_value,