Home > database >  What am I doing wrong here? (I'm a beginner in Python)
What am I doing wrong here? (I'm a beginner in Python)

Time:09-08

import random

choices = []

while True:

print("(enter 'q' to quit at anytime)")

user = input("Enter a choice: ")
if user == 'q':
    break

else:
    choices.append(user)

user1 = input("Enter another choice: ")
if user1 == 'q':
    break

else:
    choices.append(user1)

question = input("Would you like to add another choices? (yes/no): ")
if question == "no":
    break

print(random.choice(choices))

when I try to run in I get this error: user = input("Enter a choice: ") ^ IndentationError: unindent does not match any outer indentation level

CodePudding user response:

These IndentationErrors usually mean that you used too many or too few spaces to format your code. Python is in contrast to other programming languages sensitive to this indentation. Try removing your spaces and formatting the code newly. In the example that you typed, try using tab once to indent the whole code you pasted in the middle.

you might also want to have a look at this: IndentationError: unindent does not match any outer indentation level

CodePudding user response:

I would do it like this :)

import random

choices = []

flag = True

while flag: 
    print("(enter 'q' to quit at anytime)")
    user = input("Enter a choice: ")
    if user == 'q':
        break

    else:
        choices.append(user)

    user1 = input("Enter another choice: ")
    if user1 == 'q':
        break

    else:
        choices.append(user1)

    question = input("Would you like to add another choices? (yes/no): ")
    if question == "no":
        break
  • Related