1

Complete beginner here. I'm trying to read users' input and print the corresponding meaning I set to it using loop and as I see there is something wrong with it as it's not working as I intended. it works well for all 3 inputs as 1 but things don't look good if done else.

options = [
    ["1. opt1", "2. opt2", "3. opt3"],
    ["1. opt1", "2. opt2", "3. opt3"],
    ["1. opt1", "2. opt2", "3. opt3", "4. opt4"]
]
meaning = [
    [
        ["football"],
        ["basketball"],
        ["baseball"],
        ["Invalid"]
    ],
    [
        ["water"],
        ["cocacola"],
        ["milk"],
        ["Invalid"]
    ],
    [["human"],
     ["dogs"],
     ["cats"],
     ["robots"]
     ]
]
number = [1, 2, 3]
#question 1 and their options displayed here
number[0] = int(input(
    "Type the number you see in front of the option you see above: "))
#question 2 and their options displayed here
number[0] = int(input(
    "Type the number you see in front of the option you see above: "))
#question 3 and their options displayed herenumber[0] = int(input(
number[0] = int(input(
    "Type the number you see in front of the option you see above: "))
i = 0
j = 0
for i in range(len(options)):
    for j in range(len(meaning[i])):
        if number[i] == i+1:
            print(meaning[i][j])
            break
        else:
            j += 1
    i += 1
1
  • 1
    Might be a lot simpler than you have here. Did you want something like: Give user options. Collect User options. Print User options. Commented Apr 29, 2022 at 5:56

2 Answers 2

2

Use the Answer of Константин Ушаков. And: You have a failure in the for-loops: try it with:

if number[i] == j+1:
Sign up to request clarification or add additional context in comments.

Comments

1

If you want to take answer to second and third meaning, then consider to user

number[1] = int(input(...))
number[2] = int(input(...))

instead of

number[0] = int(input(...))

1 Comment

oh that was accidental. thanks, it has been helpful but I had already corrected the one you suggested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.