You are on page 1of 2

import random

def remark(score):
    if score==5:
        print("Outstanding!")
    elif score==4:
        print("Excellent!")
    elif score==3:
        print('Good')
    elif score==2:
        print("Read more to score more")
    elif score==1:
        print("Needs to take interest")
    else:
        print("General knowledge will always help you. Take it seriously.")
       
def score(answers):
    correct_answers = 0
    for answer in answers:
        if answer:
            correct_answers += 1
    return correct_answers

def gk_quiz():
    print("Welcome To the Quiz!")
    questions = [
        {
            "question": "Which planet is known as the 'Red Planet'?",
            "options": ["Mars", "Jupiter", "Venus", "Saturn"],
            "answer": 0
        },
        {
            "question": "What is the largest organ in the human body?",
            "options": ["Liver", "Brain", "Skin", "Heart"],
            "answer": 2
        },
        {
            "question": "Which country is known as the 'Land of the Rising Sun'?",
            "options": ["China", "Japan", "India", "Thailand"],
            "answer": 1
        },
        {
            "question": "Who painted the Mona Lisa?",
            "options": ["Leonardo da Vinci", "Pablo Picasso", "Vincent van Gogh", "Michelangelo"],
            "answer": 0
        },
        {
            "question": "Who is the GOAT in Football?",
            "options": ["Zlatan Ibrahimović", "Cristiano Ronaldo", "Lionel Messi", "Neymar Jr."],
            "answer": 1
        }
    ]
   
    random.shuffle(questions)
   
    user_answers = []
    for i, question in enumerate(questions):
        print(f"\nQuestion {i+1}: {question['question']}")
        for j, option in enumerate(question['options']):
            print(f"{j+1}. {option}")
        user_input = int(input("Enter your answer (1-4): "))
        user_answers.append(user_input - 1)
   
    quiz_score = score([user_answers[i] == question['answer'] for i, question in
enumerate(questions)])
   
    print("\nQuiz Results")
    print("============")
    for i, question in enumerate(questions):
        print(f"Question {i+1}: {question['question']}")
        print(f"Your answer: {question['options'][user_answers[i]]}")
        print(f"Correct answer: {question['options'][question['answer']]}\n")
   
    print(f"Your score: {quiz_score}/{len(questions)}")
    remark(quiz_score)
# Run the quiz
gk_quiz()

You might also like