python - 自动打印姓氏

标签 python

我想在输入名字后自动打印姓氏。

first_name = ("ata","amina","aarifa")
last_name = ("gowani","rajani","gowani")
print ("enter your first name")
first_name = input()
print ("your last name  is", (last_name ))

最佳答案

根据您输入的内容打印姓氏。如果它出现在first_name_list列表中,则获取索引并使用该索引从last_name_list打印。

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 ))

关于python - 自动打印姓氏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54643115/

相关文章:

python - 如何使用 Nginx 提供 Flask 静态文件?

python - 删除多个文件夹中的相同文件(python)

c++ - 在 C++ 应用程序中添加脚本

Python:Longest Plateau Problem:找到最长连续等值序列的长度和位置

python - 匹配多个包含括号内文本的完整 HTML 段落

python - 在函数调用结果上调用 "del"导致 "SyntaxError: can' t 删除函数调用”

python - 为什么在使用 werkzeug 运行 Flask 应用程序时日志记录不起作用?

python - 用 C++ 绘制图形

python - 如何检查第一个列表是否以相同的顺序出现在第二个列表中的某个位置

python - nltk.tree.Tree 对象如何生成树的字符串表示形式?