I2P (S) Quiz Game Lesson 2

General Geography Quiz – Final Version: 

aGlobalVar = 0
def func_mainquiz():
    vName = input(print("Hello there. What is your name?"))
    vAnswer = input(print("I hope you are having a good day,", vName,". Would you like to test yourself on geography? Yes = 1, No = 2"))
    while vAnswer == "1":
        import I2PGeoQuiz
    else:
        print("That’s too bad. See you again!")
        aGlobalVar = 1
print(func_mainquiz())
I2P GEOQUIZ
aGlobalVar = 0
globalScore = 0
vQuestions = open("QuizQuestions.txt")
with vQuestions as questions:
    vLines = questions.read().splitlines()
    #The with statement in Python simplifies the process of opening and closing a text file. Using the with statement, it's easier and more convenient because it opens, reads, and then closes a file
    #splitlines() is a way to separate strings in code. In this case of a text file, it helped get rid of the confusing \n's
def func_q1():
    global globalScore
    vQ1 = input(print(vLines[0:5]))
    if vQ1 == "2":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 2, Vatican City.")
def func_q2():
    global globalScore
    vQ2 = input(print(vLines[5:10]))
    if vQ2 == "3":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 3, Tokyo in Japan.")
def func_q3():
    global globalScore
    vQ3 = input(print(vLines[10:15]))
    if vQ3 == "4":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 4, Tallinn.")
def func_q4():
    global globalScore
    vQ4 = input(print(vLines[15:20]))
    if vQ4 == "2":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 2, South.")
def func_q5():
    global globalScore
    vQ5 = input(print(vLines[20:25]))
    if vQ5 == "2":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 2, Pacific Ocean.")
def func_q6():
    global globalScore
    vQ6 = input(print(vLines[25:30]))
    if vQ6 == "4":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 4, Colorado, New Mexico, Arizona, and Utah.")
def func_q7():
    global globalScore
    vQ7 = input(print(vLines[30:35]))
    if vQ7 == "2":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 2, Nevada.")
def func_q8():
    global globalScore
    vQ8 = input(print(vLines[35:40]))
    if vQ8 == "3":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 3, Ulaanbaatar.")
def func_q9():
    global globalScore
    vQ9 = input(print(vLines[40:45]))
    if vQ9 == "4":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 4, Sydney.")
def func_q10():
    global globalScore
    vQ10 = input(print(vLines[45:50]))
    if vQ10 == "3":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 3, Oceania.")
def func_q11():
    global globalScore
    vQ11 = input(print(vLines[50:55]))
    if vQ11 == "2":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 2, the Nile River")
def func_q12():
    global globalScore
    vQ12 = input(print(vLines[55:60]))
    if vQ12 == "3":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 3, England, Scotland, Wales, and Northern Ireland.")
def func_q13():
    global globalScore
    vQ13 = input(print(vLines[60:65]))
    if vQ13 == "4":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is 4, five.")
def func_q14():
    global globalScore
    vQ14 = input(print(vLines[65:70]))
    if vQ14 == "3":
        print("Correcto!")
        globalScore = globalScore + 1
else:
        print("Nope. The correct answer is C, United States and Russia.")
def func_q15():
    global globalScore
    vQ15 = input(print(vLines[70:75]))
    if vQ15 == "1":
        print("Correcto!")
        globalScore = globalScore + 2
print("Congratulations! You scored", globalScore," out of 16.")
        print(func_restart())
    else:
        print("Nope. The correct answer is 1, Arizona.")
        print("Congratulations! You scored", globalScore," out of 16")
        print(func_restart())
def func_geoquiz():
    print(func_q1(),func_q2(),func_q3(),func_q4(),func_q5(),func_q6(),func_q7(),func_q8(),func_q9(),func_q10(),func_q11(),func_q12(),func_q13(),func_q14(),func_q15())
def func_restart():
    global aGlobVar
    vRestart = input(print("""Would you like to restart again? Yes (1), no (2)"""))
    if vRestart == "1":
        print(func_geoquiz())
    if vRestart == "2":
        aGlobalVar = 1
print(func_geoquiz())

Final Pseudo Code and Mindmap

unnamed

Leave a Reply

Your email address will not be published. Required fields are marked *