[Python] How do I match a user input with an index to get the value of said index? [duplicate]

Discussão em 'Python' iniciado por Stack, Fevereiro 8, 2025.

  1. Stack

    Stack Membro Participativo

    Here's my code,

    value = [sword.cost, hammer.cost, sickle.cost]
    uInput = int(input("Choose: "))

    for index, thing in enumerate(value):
    a = index
    uInput = uInput -1
    if uInput in a:
    print(thing)


    But it's raising an error and I'm not sure what to do from this point.

    Basically I'm trying to get the user input to be a number and that number will be subtracted by 1 to match one of the indexes and then it has to find which index that is and then return the value aka cost.

    Continue reading...

Compartilhe esta Página