Viewing a single comment thread. View all comments

nulloperation wrote (edited )

You could also do stuff with an array or some lists to contain it all in the one loop, but I don't know the syntax well enough to write it off the top of my head.

Here's my attempt at that. If you want to add more questions, just add them to the questions list.

questions=[
        {"q":"famous blue anti-civ hedgehog?","a":"sonic"},
        {"q":"blue men who live in mushrooms?","a":"smurfs"}
]

def ask(question):
    print(question["q"])
    return input().lower() == question["a"].lower()

def ask_all(questions):
    if questions:
        if ask(questions[0]):
            return ask_all(questions[1:])
        else:
            return False
    else:
        return True


if ask_all(questions):
    print('succes')
else:
    print('fail')

@kokoaitu You should really use code blocks for pasting code, especially a language like Python with whitespace sensitive syntax. Also, I think your do ... until construct is not really quite Python.

@raddleboy If you're new to Python or programming in general, I'd suggest sticking with plain Python (without GUI libraries) while you're getting to know the language. Using time.sleep() in the same thread as the GUI can be problematic as it can lock up the GUI.

Extra points if anyone can do this

3