Python Forum
New zealand Trivia Quiz
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New zealand Trivia Quiz
#1
Can someone make or help with creating a NZ Trivia Quiz Using only one for loop, lists, While True loop and no use of functions.

Create a New Zealand trivia quiz. The game will consist of multiple-choice questions about New Zealand. The program needs to do the following. At th e start of the program, ask for the user’ s nam e and use th is throughout th e program. After you have the user’ s name, greet them and give them the rules/instructions for the quiz. Th e quiz is only meant for children from 5 to 11 years of age. If th e user does not fit within th is age range, give them the optio n of quitt ing the quiz or continuing. The quiz should consist of at least three questions. Use the examples in this brief. Th e user will be show n a different set of questions, depending on their age. If they are: o7-years-old and younger, they should see the Quiz A questionsoolder than 7, they should see the Quiz B questions.Hint: To do this you will need to set up four lists – two for each set of questions and two for each set of answers. If a user gets a question correct, congratulate them and increment their score. If the user gets a question wrong, tell them the correct answer. Do not increment their score. At the end of the quiz, tell the user what their score is.
Reply
#2
What have you tried?
Reply
#3
(Mar-23-2023, 02:07 AM)deanhystad Wrote: What have you tried?

#welcome banner
def welcome_banner():
    print("| -------------------------------------------- |")
    print("|                                              |")
    print("|     welcome to New Zealand Trivia quiz       |")
    print("|                                              |")
    print("| -------------------------------------------- |")
#goodbye banner
def goodbye_banner():
    print("| ----------------------------------------- |")
    print("|                                           |")
    print("|           thanks for playing              |")
    print("|                                           |")
    print("| ----------------------------------------- |")


# The Required lists are below
quiz_A = [
"what is the capital of New Zealand?\n(a) wellington\n(b) Auckland\n(c) christchurch\n\n",
"which city is known as The Garden City?\n(a) wellington\n(b) Auckland\n(c) christchurch\n(d) Hamilton\n\n",
"Where did L&P soda originally come from?\n(a) wellington\n(b) Auckland\n (c) christchurch\n(d) Paeroa\n\n"
]
quiz_B = [
"Which New Zealand city houses the beehive?\n(a) wellington\n(b) Auckland\n(c) christchurch\n(d) Hamilton\n\n",
"Which town has a giant carrot as a landmark?\n(a) Taihape\n(b) Waihi\n(c) Ohakune\n\n",
"When was the treaty of Waitangi signed\n(a) 1815\n(b) 1840\n(c) 1855\n(d) 1875\n\n"
]
Questions = [
    question(quiz_A[0], "a"),
    question(quiz_A[1], "c"),
    question(quiz_A[2], "d"),
    ]
Questions = [
    question(quiz_B[0], "a"),
    question(quiz_B[1], "c"),
    question(quiz_B[2], "b"),
    ]
quiz_A_ans = ["1. A", "2. C", "3. D"]
quiz_B_ans = ["1. A", "2. C", "3. B"]
points = 0
current = 0
play = "y"
welcome_banner()
# Asking the user for their name
name = input("Hello player, what is your name? - ")
# Welcoming them to the game
print(f"Welcome {name} to the New zealand Trivia Quiz")
# Explaining the rules
print(" This is a multi choice game for people between the age of 5 to 11")


while True:
    try:
            age = int(input("Please enter your age: "))

            if age>= 5 and age<=11:
                break
            else:
                print("Your not in the suitable age range.")
                continues = input("do you want to continue enter y/n:")
                if continues == ("n"):
                    goodbye_banner()
                    break
                else:
                    break
             

    except ValueError:
        print("Please only enter an integer")

        while play == "y":
            if age<=7:
                question = input(quiz_A[current])
               
                print("Well done you got it right")
                   
            elif age>=8:
                questions = input(quiz_B[current])
Reply
#4
(Mar-23-2023, 03:07 AM)SEWII Wrote:
(Mar-23-2023, 02:07 AM)deanhystad Wrote: What have you tried?

#welcome banner
def welcome_banner():
    print("| -------------------------------------------- |")
    print("|                                              |")
    print("|     welcome to New Zealand Trivia quiz       |")
    print("|                                              |")
    print("| -------------------------------------------- |")
#goodbye banner
def goodbye_banner():
    print("| ----------------------------------------- |")
    print("|                                           |")
    print("|           thanks for playing              |")
    print("|                                           |")
    print("| ----------------------------------------- |")


# The Required lists are below
quiz_A = [
"what is the capital of New Zealand?\n(a) wellington\n(b) Auckland\n(c) christchurch\n\n",
"which city is known as The Garden City?\n(a) wellington\n(b) Auckland\n(c) christchurch\n(d) Hamilton\n\n",
"Where did L&P soda originally come from?\n(a) wellington\n(b) Auckland\n (c) christchurch\n(d) Paeroa\n\n"
]
quiz_B = [
"Which New Zealand city houses the beehive?\n(a) wellington\n(b) Auckland\n(c) christchurch\n(d) Hamilton\n\n",
"Which town has a giant carrot as a landmark?\n(a) Taihape\n(b) Waihi\n(c) Ohakune\n\n",
"When was the treaty of Waitangi signed\n(a) 1815\n(b) 1840\n(c) 1855\n(d) 1875\n\n"
]
Questions = [
    question(quiz_A[0], "a"),
    question(quiz_A[1], "c"),
    question(quiz_A[2], "d"),
    ]
Questions = [
    question(quiz_B[0], "a"),
    question(quiz_B[1], "c"),
    question(quiz_B[2], "b"),
    ]
quiz_A_ans = ["1. A", "2. C", "3. D"]
quiz_B_ans = ["1. A", "2. C", "3. B"]
points = 0
current = 0
play = "y"
welcome_banner()
# Asking the user for their name
name = input("Hello player, what is your name? - ")
# Welcoming them to the game
print(f"Welcome {name} to the New zealand Trivia Quiz")
# Explaining the rules
print(" This is a multi choice game for people between the age of 5 to 11")


while True:
    try:
            age = int(input("Please enter your age: "))

            if age>= 5 and age<=11:
                break
            else:
                print("Your not in the suitable age range.")
                continues = input("do you want to continue enter y/n:")
                if continues == ("n"):
                    goodbye_banner()
                    break
                else:
                    break
             

    except ValueError:
        print("Please only enter an integer")

        while play == "y":
            if age<=7:
                question = input(quiz_A[current])
               
                print("Well done you got it right")
                   
            elif age>=8:
                questions = input(quiz_B[current])
This is what I have so far but when I don't know how to continue with my code. Also when I enter an age above 11 or below 5 and when it comes up with the do you want to play again it doesn't work.
Reply
#5
You write code in the wrong order. Focus on quiz logic first, then add stuff like banners and getting names and ages.

Keeping your existing program as a reference, start a new program that just does the quiz with just one set of questions.

When you have the quiz working, write the code that lets you select which quiz questions to use based on age input.

When you get that working add in the part where you ask if they want to quit if they are too old or too young.

It is far easier to build out from the center than it is to build in from the outside.

I would expect the program to look something like this:
START play_again_loop
    get age
    if age in range:
        if age < 7
            select young questions
        else
            select old questions

        START quiz loop
            ask question
            get answer
            update score
        END quiz loop

    else if age not in range
         ask to exit
         if yes exit

     ask if play again
     if no exit
END play again loop
Reply
#6
(Mar-23-2023, 04:04 AM)deanhystad Wrote: You write code in the wrong order. Focus on quiz logic first, then add stuff like banners and getting names and ages.

Keeping your existing program as a reference, start a new program that just does the quiz with just one set of questions.

When you have the quiz working, write the code that lets you select which quiz questions to use based on age input.

When you get that working add in the part where you ask if they want to quit if they are too old or too young.

It is far easier to build out from the center than it is to build in from the outside.

I would expect the program to look something like this:
START play_again_loop
    get age
    if age in range:
        if age < 7
            select young questions
        else
            select old questions

        START quiz loop
            ask question
            get answer
            update score
        END quiz loop

    else if age not in range
         ask to exit
         if yes exit

     ask if play again
     if no exit
END play again loop

Ok I kind of understand what you mean and it makes sense but for the part where you mentioned START quiz loop
ask question
get answer
update score
END quiz loop

can you do that part for me?
and this part else if age not in range
ask to exit
if yes exit

ask if play again
if no exit.

Or like starting it off for me please.
Reply
#7
name = input("Hello user, What is your name? ")

# Welcome the user by their name to New Zealand Trivia quiz

print(f"Welcome {name}, to New Zealand Trivia quiz")

# Give instruction of this game

print(

    "This quiz is designed for 5 to 11 years old consisting of multiple choice       questions about New Zealand."

)

# Score count of the quiz

score = 0

# Checking if user is at a suitable range for this quiz if not they have a choice to quit

while True:

   try:

        age_num = int(input("What is your age? "))

        if age_num < 5 or age_num > 11:

            print("You are not at a suitable age range for this quiz")

            loop = int(

                input(

                    "Would you like to continue or quit? Please enter 1 for yes/2 for no:"

                )

            )

            if loop == 2:

                quit_banner()

                break

    except ValueError:

        print("Please anter an integer number")

 

    # Display the quiz designed for age 7 or under

    if age_num <= 7:

        for x in range(2, len(ques_A)):

            firstAquestion = ques_A[0]

            answer_A = input(firstAquestion)

            if answer_A == ques_A_ans[0]:

                print("CORRECT!!")

                score = score + 1

            else:

                print(

                    f"Sorry your answer is incorrect, the correct answer is {ques_A_ans[0]}"

                )

        for x in range(2, len(ques_A)):

            secAquestion = ques_A[1]

            answer_A = input(secAquestion)

            if answer_A == ques_A_ans[1]:

                print("CORRECT!!")

                score = score + 1

            else:

                print(

                    f"Sorry your answer is incorrect, the correct answer is {ques_A_ans[1]}"

                )

        for x in range(2, len(ques_A)):

            thirdAquestion = ques_A[2]

            answer_A = input(thirdAquestion)

            if answer_A == ques_A_ans[2]:

                print("CORRECT!!")

                score = score + 1

            else:

                print(

                    f"Sorry your answer is incorrect, the correct answer is {ques_A_ans[2]}"

                )

        else:

            print(f"Your final score is {score}, you got {score} questions right.")

            goodbye_banner()

            break
Reply
#8
This is what I have now how do I only use one for loop and add the other age level quiz. Can someone do it for me without the use of functions.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Two Questions Regarding My Trivia Game martin28 1 2,366 Aug-19-2018, 02:07 PM
Last Post: martin28
  Questions about the GET and POST submission form Functions in Python for a Trivia Gam martin28 8 3,989 Aug-05-2018, 09:47 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020