Home > OS >  How can I turn a string into a call to a variable and retrieve the variable contents?
How can I turn a string into a call to a variable and retrieve the variable contents?

Time:07-24

I'm trying to call a different variable based on the input the function receives, but I don't know how to change the text based on the input. How can I turn a string into a call to a variable to make my text say "you chose" and based on the decision variable, a certain choice?

def blab(decision):
    Choice_0 = "Python Ideas"
    Choice_1 = "Website Ideas"
    Choice_2 = "Discord Ideas"
    Choice_3 = "Game Ideas"
    Choice_4 = "Robot Ideas"
    real_choice = Choice_   decision

    deci = input(F"You chose {real_choice}")

CodePudding user response:

Why not use a list?

def blab(decision):
    choices = [
        "Python Ideas"
        "Website Ideas"
        "Discord Ideas"
        "Game Ideas"
        "Robot Ideas"
    ]
    real_choice = choices[decision]

    deci = input(F"You chose {real_choice}")
  • Related