Jump to content


Check out our Community Blogs

pebz5

Member Since 27 Jun 2011
Offline Last Active Jul 16 2011 08:34 AM
-----

Topics I've Started

Beginner's syntax error

27 June 2011 - 04:20 PM

Hi everyone,
I'm a new poster here, and a complete and total beginner at programming. I decided to start with Python since I'd read that it was an easy one to learn for beginners. I'm using some online tutorials, and one of the exercises was to work on some code for a small quiz program. However, I keep getting a strange syntax error, and I can't get the reason. I was hoping that someone experienced could take a look and tell me what I'm missing? Thanks a lot.
def main_menu():
    print("1. Print the menu")
    print("2. Take the test")
    print("3. Quit the program:")
def get_questions():
    return[["What color is the daytime sky on a clear day? ", "blue"],
            ["What is the answer to life, the universe and everything? ", "42"],
            ["What is a three letter word for mouse trap? ", "cat"],
            ["What noise does a truly advanced machine make?", "ping"]]
def check_question(question_and_answer):
        question = question_and_answer[0]
        answer = question_and_answer[1]
        given_answer = input(question)
        if answer == given_answer:
            print("Correct")
            return True
        else:
            print("Incorrect, correct was:", answer)
            return False

def run_test(questions):
    if len(questions) == 0:
        print("No questions were given.")
        return
    index = 0
    right = 0
    while index < len(questions):
        if check_question(questions[index]):
            right = right + 1
        index = index + 1
    print("You got", right " 100 / len(questions),\
        % right out of", len(questions))
choice = 1
while choice != 3:
    if choice == 1: #Here's where I get a syntax error, in a small space right before the if.
        main_menu()   
    elif choice == 2:
        run_test(questions)
    print()
    choice = int(input("Choose an option: "))
print("Goodbye")


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download