rhys1619 0 Newbie Poster

hi there what i've tried a lot is to make it so at the start of the quiz it asks the user there age. if the user is under 5 they will only be asked 5 questions and if there over 5 they will be asked all 10

#rhys translation quiz
#the list of questions that will be asked
question_list = [
(   "What is Kia ora in english",
    "a. Hello\nb. Bye\nc. Greetings\nd. See ya\n",
    "a"),
(   "What is tena rawa atu koe in english",
    "a. Give it\nb. bye\nc. Thank you\nd. See ya\n",
    "c"),
(   "What is rorohiko in english",
    "a. TV\nb. Microwave\nc. Oven\nd. Computer\n",
    "d"),
(   "What is taraka in english",
    "a. Van\nb. Car\nc. Truck\nd. bus\n",
    "c"),
(   "What is kāri in english",
    "a. Deck\nb. Game\nc. Suit\nd. Card\n",
    "d"),
(   "What is kai in english",
    "a. Food\nb. Drink\nc. Soup\nd. Water\n",
    "a"),
(   "What is kiriata in english",
    "a. Show\nb. Film\nc. Song\nd. Book\n",
    "b"),
(   "What is makawe in english",
    "a. Face\nb. Hair\nc. Neck\nd. Beard\n",
    "b"),
(   "What is tau in english",
    "a. Letter\nb. Number\nc. Space\nd. Shape\n",
    "b"),
(   "What is wini in english",
    "a. Win\nb. Lose\nc. Try again\nd. Quit\n",
    "a"),
]
play_again = True
while play_again:
    score = 0
#intro and instruction
print ("""Welcome to the translation quiz...""")
#new input function here. You can make the message more or less formal
age = int(input("Please enter your age: ))
print ("""You will be ask a series of questions and have 2 tries per questions
If you get the correct answer you will get one point, half a point for getting it
your second try and zero points if you get it wrong twice.
GOOD LUCK!!!
""")

counter = 0
for question, options, correct in question_list:
    print(question)
    print(options)
    if counter == 5 and age <= 5:
     #if you reach the 5th question then you want to break the for loop.
        break

    #increment the variable to keep track of position
    counter +=1
        #user will have to enter a,b,c or d for there answer
        response = input("Hit 'a', 'b', 'c' or 'd' for your answer\n")
        #simple, if answer is correct print correct and move on to next question, if not try again
        if response.lower() == correct:
            print ("Correct\n")
            score = score + 1
            #this will say there wrong and they will get another try. if they get it right they get 0.5 points and if not they move on to the next question
        else:
            print("Wrong. Try again.\n")
            response = input("Hit 'a', 'b', 'c' or 'd' for your answer\n")
            if response.lower() == correct:
                print ("Correct\n")
                score = score + 0.5
            else:
                print("Wrong. You ran out of attempts\n")
                #this will print the users final score out of 10
    print ("Your score was", str (score)+"/10")
    #this is a restart. if the user says y then they restart if not the program ends.
    response = input("Do you want to play again (y/n)?").strip().lower()
    if response not in ('', 'y', 'yes'):
        play_again = False 

Dani AI

Generated

Good start, — the idea is clear and most of the pieces are there. The script has three recurring issues: a syntax error on the age input line, mis-indentation that moves the question/score logic out of its intended blocks, and the age-gate/counter logic so it either never or incorrectly stops after five questions. There is also a small logic bug in the replay prompt (empty input currently behaves like "yes") and the score print always shows “/10” even when only five questions were asked.

A straightforward, robust fix is to:

  • Validate the age with a try/except loop so non-numeric input does not crash the program.
  • Decide the number of questions once (for example max_questions = 5 if age < 5 else len(question_list)) and iterate over question_list[:max_questions]. That avoids fragile counter math and off-by-one checks.
  • Keep the question/attempt/scoring block fully inside the for-loop and print the final score after the loop. Reset score and related state at the start of each play-through. Make the replay check explicit (continue only on y or yes).

Example (minimal) pattern to implement the age gate and safe iteration:

def get_age():
    while True:
        try:
            a = int(input("Enter your age: "))
            if a >= 0:
                return a
        except ValueError:
            pass
        print("Please enter a whole non-negative number.")

age = get_age()
max_questions = 5 if age < 5 else len(question_list)

for qnum, (q, opts, ans) in enumerate(question_list[:max_questions], start=1):
    print("Q{}:".format(qnum))
    print(opts)
    # ask, validate 'a'/'b'/'c'/'d', award 1 or 0.5, etc.

Extra tips: normalize user answers with .strip().lower(), explicitly validate allowed choices, and compute the denominator from max_questions when printing the final score. If staying with Python 2, use raw_input() instead of input().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.