python - 如何从用户那里获取输入,然后检查多个列表是否与输入匹配
问题描述
我是 Py 的一个相当初学者,虽然我正在尝试自动化某项任务,我们正在配音一个 webtoon 系列,我们需要训练,因为我们很多,我需要一个程序,检查用户输入一个数字,然后检查倍数列表(第 1 (3) 集)中的字符数。
我还需要是否有人愿意提供更多帮助,用名字来做这件事,我几乎明白了,然后卡住了,我很生气,所以我删除了所有内容,但是 ht 代码很糟糕,所以没有悔意。所以你输入一堆名字,它会输出带有这些名字的剧集。
ep_1 = [3] these are the numbers of character in an episode
ep_2 = [1]
ep_3 = [1]
ep_4 = [1]
ep_5 = [3]
eps = ep_1.extend(ep_2 + ep_3 + ep_4)
print("version : 1.0 : Dispo j'usqu'a l'episode 50")
print(" ")
print(" ")
print(" ")
print("Noms des personnages a utiliser : john isen arlo doc directeur elaine sera cecile blyke")
print(" ")
print(" ")
print(" ")
choix = input("Numbers of characters, or names of characters ?")
if choix := ("nombre"):
nombre_persos = int(input("how many characters ? : "))
if nombre_persos in eps:
print("oui") this just help me verify the if statement, i just dont know what to do next, and even if im doing anything good
解决方案
您可以使用enumerate
. 这是代码:
ep_1 = [3]
ep_2 = [1]
ep_3 = [1]
ep_4 = [1]
ep_5 = [3]
eps = ep_1 + ep_2 + ep_3 + ep_4
print("version : 1.0 : Dispo j'usqu'a l'episode 50")
print(" ")
print(" ")
print(" ")
print("Noms des personnages a utiliser : john isen arlo doc directeur elaine sera cecile blyke")
print(" ")
print(" ")
print(" ")
choix = input("Numbers of characters, or names of characters ?")
if choix == ("nombre"):
nombre_persos = int(input("how many characters ? : "))
if nombre_persos in eps:
print("oui")
eps2 = eps
for (i, item) in enumerate(eps2, start=1):
if item == nombre_persos:
print('ep_'+str(i))
并查看此枚举: https ://docs.python.org/3/library/functions.html#enumerate
推荐阅读
- python - 循环浏览消息集合时从一个用户集合中获取信息 - Firestore
- flutter - No Icon but it can be tested
- python - 使用 pandas.DataFrame.plot() 时如何显示所有 xticks?
- java - 有没有办法将外部文件“信息”保存到java中的数组中?
- wordpress - 插件 gatsby-source-wordpress 中的 ETIMEDOUT 错误
- c - 问题涉及N x N的网格,并且有一定数量的小偷和强盗。数一数有多少小偷被抓
- c# - CSVHelper 将值传递给 MapClass
- r - 测试某些变量(不同版本)是否出现在数据中
- wordpress - 自定义元框字段不显示 HTML
- xml - 如何使用 expath 和 Xquery 获取 CSV 文件?