以下是我编的程序,要说的话都在图片里,请指教!
用户:
1101110010100011查看:4 回复:5 评论:4 创建时间:2022-07-21T21:59:31
回复
上一页第 1 页 / 共 1 页下一页
#逸一时误一世#name_l = list(name_age_ID_number.keys())
#接到第20行
if c in name_l:
print('{},{}岁,身份证号{}'.format\
(c,name_age_ID_number[c],name_age_ID_number[c+'ID']))
点赞1
一门鸽鸽你可以嵌套字典
但不要给一个人的两个信息弄两个键在同一个字典里
你说,
要是有两个人,
一个叫 王小美 ,另一个偏要叫 王小美ID 咋办
所以建议用字典嵌套:
{'王小美':{'age':1000,'id':'331044920292010300'},'路人甲':{'age':25,'id':'50294810485920530'}}
点赞0
1101110010100011此程序的终极版本
代码:
#通过字典完成的一个简单程序/A simple program done with a dictionary #非喵人士可以通过列表完成这个程序/Non-badass people can complete this program with a list
D = 0 name_age_ID_number = {'王明': '34岁', '李大忠': '43岁', '马喵': '11岁', '王明ID': '身份证号码:123946148295629374', '李大忠ID': '身份证号码1473喵91喵63817263'\ ,'马喵ID':'身份证号码237428462937462184'}# 身份证号码是伪的,别想那么多/Id Card number is false, don't think so much print('初始人名:王明、李大忠、马喵') while 1: # 重复执行/Repeat execution if(D == 0):#中文版 a = str(input('请输入服务:')) if(a == '添加人名'): name2 = str(input('请输入人名:')) age2 = str(input('请输入年龄:')) name_age_ID_number[name2] = age2 ID_number2 = str(input('请输入身份证号码:')) name_age_ID_number[name2 + 'ID'] = '身份证号码:' print('添加完成') if(a == '查询身份'): c = str(input('请输入人名:')) name_l = list(name_age_ID_number.keys()) if c in name_l: print('{},{},{}'.format\ (c, name_age_ID_number[c], name_age_ID_number[c+'ID'])) if(a == '语言设置'): C = str(input('请输入语言:')) if(C == 'English'): print('\033c', end='') name_age_ID_number = {'Wing ming': '34years old', 'Li dazhong': '43years old', 'Maniubi': '11years old', 'WID': 'ID number:123946148295629374', 'LID': 'ID number:1473喵91喵63817263'\ ,'MID':'ID number:237428462937462184'} print('IInitial name:Wang ming,Li dazhong,Maniubi') D = 1 else: a = str(input('Please enter the service:')) if(a == 'Add a person name'): name2 = str(input('Please enter a name:')) age2 = str(input('Please enter age:')) name_age_ID_number[name2] = age2 ID_number2 = str(input('Please enter your identity card number:')) name_age_ID_number[name2 + 'ID'] = 'ID number:' print('Add done') if(a == 'Check identity'): c = str(input('Please enter a name:')) name_l = list(name_age_ID_number.keys()) if c in name_l: print('{},{},{}'.format\ (c, name_age_ID_number[c], name_age_ID_number[c+'ID'])) if(a == 'Language setting'): C = str(input('Please enter the language:')) if(C == '中文简体'): print('\033c', end='') name_age_ID_number = {'王明': '34岁', '李大忠': '43岁', '马喵': '11岁', '王明ID': '身份证号码:123946148295629374', '李大忠ID': '身份证号码1473喵91喵63817263'\ ,'马喵ID':'身份证号码237428462937462184'} print('初初始人名:王明、李大忠、马喵') D = 0 感谢:田所·布兰度、中子星000
点赞0