import random
import time

quiz_questions = {
    "How many letters are there in the Arabic language?": {
        "choices": ["A: 20", "B: 26", "C: 30", "D: 28"],
        "answer": "D"
    },
    "What is the fastest animal in the world?": {
        "choices": ["A: Lion", "B: Shark", "C: Cheetah", "D: Owl"],
        "answer": "C"
    },
    "Where is the largest tower in the world located?": {
        "choices": ["A: Dubai", "B: Riyadh", "C: Paris", "D: Abu Dhabi"],
        "answer": "A"
    },
    "What is the capital of the Kingdom of Saudi Arabia?": {
        "choices": ["A: Jeddah", "B: Mecca", "C: Riyadh", "D: Dammam"],
        "answer": "C"
    },
    "What is the heaviest animal on planet Earth?": {
        "choices": ["A: The blue whale", "B: The elephant", "C: The giraffe", "D: The turtle"],
        "answer": "A"
    }
}

def play_question(question, choices):
    print(question)
    for choice in choices:
        print(choice)
    print()

def quiz_game(questions, num_questions, time_per_question):
    shuffled_questions = list(questions.items())
    random.shuffle(shuffled_questions)
    selected_questions = shuffled_questions[:num_questions]

    score = 0

    for question, data in selected_questions:
        play_question(question, data["choices"])
        user_answer = None
        start_time = time.time()
        
        
        while user_answer is None and time.time() - start_time < time_per_question:
            user_answer = input("Enter your answer (A, B, C, or D): ").upper()

        
        time_taken = time.time() - start_time
        print("Time taken to answer:", round(time_taken, 2), "seconds")

        if user_answer == data["answer"]:
            print("Correct!\n")
            score += 1
        else:
            print("Incorrect! The correct answer is:", data["answer"], "\n")

    print("Quiz complete!")
    print("Your score:", score, "/", num_questions)

if __name__ == "__main__":
    num_questions = int(input("How many questions do you want to answer? "))
    time_per_question = int(input("Enter time allowed per question (in seconds): "))
    quiz_game(quiz_questions, num_questions, time_per_question)
