Home > Enterprise >  Whats the problem with this loop im trying in python?
Whats the problem with this loop im trying in python?

Time:04-29

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

CodePudding user response:

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(...))

CodePudding user response:

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

if number[i] == j 1:
  • Related