Trying to play with lists and i want to only enter a number to get one out of 6 alternatives. This is the code, maby you will understand where i want to get: alts = [ "alt1", "alt2", "alt3", "alt4", "alt5", "alt6", ] question = input("what alt? ") answer = input(question) def question(question): if answer == 1: print(alts[0]) elif input("2"): print(alts[1]) else: print("and so on") ------------------------------------ Of course its not full, but can someone write down a full code fo this?
12/14/2018 5:25:49 PM
johan suup5 Answers
New Answeran easier way would be to get the input, convert to int, save to a variable, and print the alts at that index. print(alts[input]) no need for that control statement
got it: alts = [ "alt1", "alt2", "alt3", "alt4", "alt5", "alt6", ] answer = int(input()) if (answer >= 1 and answer <= 6): print(alts[answer - 1]) wery much thanks!
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message