first_name_list = ("ata","amina","aarifa")
last_name_list = ("gowani","rajani","gowani")
print ("enter your first name")
first_name = input()
if first_name in first_name_list:
index = first_name.index(first_name)
last_name = last_name_list[index]
print ("your last name is", (last_name ))
first_name = ("ata","amina","aarifa")
last_name = ("gowani","rajani","gowani")
mapping = dict(zip(first_name, last_name))
print("enter your first name")
first_name = input()
try:
print("your last name is", mapping[first_name])
except KeyError:
print("your name is not registered")
根据您的输入打印姓氏。如果它出现在第一个名称列表中,则使用索引并使用该索引从最后一个名称列表打印
通过压缩两个列表并将结果序列传递给dict构造函数,可以创建一个将名字映射到姓氏的dict:
相关问题 更多 >
编程相关推荐