简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM