Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am wanting to join the Royal Air Force and thought as a good way to prepare I should code myself a quiz about their aircraft.

There are 28 aircraft that I have added to the quiz. For example - 'Where is the Typhoon FGR4 based?' And then I have 7 seconds to think before the options pop up for me to answer.

Instead of the quiz just going from the first to last question in the same order each time I would like it to be shuffled.

Here is the quiz in pastebin http://pastebin.com/wxVus42W

Also when I have answered the question I would like the console to clear itself for the next question to come up.

Can anyone help?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
182 views
Welcome To Ask or Share your Answers For Others

1 Answer

dont repeat yourself!, create methods, add your question and the excepted answer as flag

import time

def create_question(question = "", answer = "", excepted = ""):
    print (question)
    time.sleep(7)
    print(answer)

    while True:
        response = input("Hit 'a', 'b', 'c' or 'd' for your answer
")

        if response == excepted:#CHANGE
            print ("Correct!
")
            break
        else:
            print("Incorrect!!! Try again.")

            while True:
                response = input("Hit 'a', 'b', 'c' or 'd' for your answer
")

                if response == excepted:#CHANGE
                    print ("Correct!
")#CHANGE
                    stop = True
                    break
                else:
                    print("Incorrect!!! The Tornado GR4 is based at RAF Marham
")#CHANGE
                    stop = True
                    break
            if stop:
                break

#first question               
create_question(question = "Where is the Tornado GR4 based?",
                answer = "a. RAF Marham
b. RAF Conningsby
c. RAF Waddington
d. RAF Church Fenton
",
                excepted = "a")
#second question                
create_question(question = "Where is the Typhoon FGR4 Based?",
                answer = "a. RAF Marham
b. RAF Conningsby
c. RAF Benson
d. RAF Wyton
",
                excepted = "b")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...