# Define the quiz questions and answers
questions = [
    {
        "question": "What is Python?",
        "options": ["A type of snake", "A high-level programming language", "A data structure", "A computer manufacturer"],
        "correct_answer": "B"
    },
    {
        "question": "Which of the following is not a valid Python data type?",
        "options": ["Integer", "String", "Float", "Ladder"],
        "correct_answer": "D"
    },
    {
        "question": "How do you write a single-line comment in Python?",
        "options": ["// This is a comment", "# This is a comment", "/* This is a comment */", "-- This is a comment"],
        "correct_answer": "B"
    },
    {
        "question": "Which of the following is used to define a function in Python?",
        "options": ["def", "function", "define", "func"],
        "correct_answer": "A"
    },
    {
        "question": "What does the 'print()' function do in Python?",
        "options": ["Reads user input", "Writes text to a file", "Displays output to the console", "Performs mathematical calculations"],
        "correct_answer": "C"
    },
    {
        "question": "How do you declare a variable in Python?",
        "options": ["var x", "let x", "x =", "x :="],
        "correct_answer": "C"
    },
    {
        "question": "Which of the following is used to create a list in Python?",
        "options": ["( )", "{ }", "[ ]", "< >"],
        "correct_answer": "C"
    },
    {
        "question": "What does the 'if' statement do in Python?",
        "options": ["Loops through a sequence", "Defines a function", "Makes decisions based on conditions", "Prints text to the console"],
        "correct_answer": "C"
    },
    {
        "question": "Which operator is used for exponentiation in Python?",
        "options": ["^", "**", "^", "%"],
        "correct_answer": "B"
    },
    {
        "question": "What is the output of '3 + 4 * 5' in Python?",
        "options": ["35", "23", "27", "60"],
        "correct_answer": "D"
    }
]

# Initialize the score
score = 0

# Function to display and grade the quiz
def run_quiz(questions):
    for i, question in enumerate(questions, 1):
        print(f"Question {i}: {question['question']}")
        for j, option in enumerate(question['options'], 1):
            print(f"{chr(64+j)}. {option}")
        user_answer = input("Your answer (A/B/C/D): ").upper()
        if user_answer == question['correct_answer']:
            print("Correct!\n")
            global score
            score += 1
        else:
            print(f"Wrong! The correct answer is {question['correct_answer']}.\n")

# Run the quiz
print("Welcome to the Python Quiz!")
run_quiz(questions)

# Display the final score
print(f"You scored {score} out of {len(questions)} questions.")

# Calculate and display the percentage score
percentage_score = (score / len(questions)) * 100
print(f"Percentage Score: {percentage_score:.2f}%")

# Provide feedback based on the score
if percentage_score >= 70:
    print("Congratulations! You did well.")
else:
    print("You might want to review your Python knowledge. Keep learning!")


Welcome to the Python Quiz!
Question 1: What is Python?
A. A type of snake
B. A high-level programming language
C. A data structure
D. A computer manufacturer
Correct!

Question 2: Which of the following is not a valid Python data type?
A. Integer
B. String
C. Float
D. Ladder
Wrong! The correct answer is D.

Question 3: How do you write a single-line comment in Python?
A. // This is a comment
B. # This is a comment
C. /* This is a comment */
D. -- This is a comment
Correct!

Question 4: Which of the following is used to define a function in Python?
A. def
B. function
C. define
D. func
Wrong! The correct answer is A.

Question 5: What does the 'print()' function do in Python?
A. Reads user input
B. Writes text to a file
C. Displays output to the console
D. Performs mathematical calculations
Wrong! The correct answer is C.

Question 6: How do you declare a variable in Python?
A. var x
B. let x
C. x =
D. x :=
Correct!

Question 7: Which of the following is used to create a list in Python?
A. ( )
B. { }
C. [ ]
D. < >
Wrong! The correct answer is C.

Question 8: What does the 'if' statement do in Python?
A. Loops through a sequence
B. Defines a function
C. Makes decisions based on conditions
D. Prints text to the console
Wrong! The correct answer is C.

Question 9: Which operator is used for exponentiation in Python?
A. ^
B. **
C. ^
D. %
Wrong! The correct answer is B.

Question 10: What is the output of '3 + 4 * 5' in Python?
A. 35
B. 23
C. 27
D. 60
Wrong! The correct answer is D.

You scored 3 out of 10 questions.
Percentage Score: 30.00%
You might want to review your Python knowledge. Keep learning!