interactive list, finish my noob code! | Sololearn: Learn to code for FREE!

+1

interactive list, finish my noob code!

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 suup

5 Answers

New Answer

+11

an 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

+2

answer=int(input()) if(answer >=1 and answer <=6): print(alts[answer-1])

+1

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!

0

ok im in over my head, back to the tutorials!:O thanks anyway!!

0

writing in python 3 btw