def types(num): try: int(num) # return '数据类型错误' print('数据类型错误') except ValueError: return num NameList = [] for i in range(5): NewName = input('请输入你要查询的名称:').replace(' ', '') if types(NewName) == NewName: if NewName in NameList: print('你输入的名称是{0},已在数据库中存在,欢迎您 {0}'.format(NewName)) else: NameList.insert(0, NewName) print('你输入的名称是{0},数据库中间不存在,你的名称{0},已经被收录在数据库中了'.format(NewName)) else: # print(types(NewName)) pass print(NameList)
python 输入名称 类型判断 list插入练习代码
猜你喜欢
转载自blog.csdn.net/tianpingxian/article/details/80265845
今日推荐
周排行