首页 > 解决方案 > 如何从用户那里获取输入,然后检查多个列表是否与输入匹配

问题描述

我是 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

标签: pythonlistinput

解决方案


您可以使用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


推荐阅读