from IPython.core.display import HTML
def load_css():
    styles = open("custom3.css", "r").read()
    return HTML(f"<style>{styles}</style>")
load_css()

Fun Conditionals Quiz!!

Conditionals Quiz

# Import necessary modules
import sys  # Module to access system-related information

# Function to ask a theoretical question and get a response
def question_with_response(prompt):
    answer = input(prompt)
    return answer

# Define the number of questions and initialize the correct answers counter
questions = 5
correct = 0

# Personalized greeting message
user_name = question_with_response("Enter your name: ")
print('Hello, ' + user_name + " you are running " + sys.executable)
ready = question_with_response("Are you ready to take a test on Python conditionals? (yes/no): ")

# HOMEWORK: Come up with different types of questions

# Question 1: Relational Operators
q1 = question_with_response("1. Which of the following is the relational operator for 'greater than'? (a) > (b) < (c) = : ")
if q1.lower() == "a":
    print("Correct!")
    correct += 1
else:
    print("Incorrect. The correct answer is (a) >.")

# Question 2: Logical Operators
q2 = question_with_response("2. Which logical operator checks if both conditions are true? (a) or (b) and (c) not : ")
if q2.lower() == "b":
    print("Correct!")
    correct += 1
else:
    print("Incorrect. The correct answer is (b) and.")

# Question 3: Conditional Expressions
q3 = question_with_response("3. What will be the result of this expression: 5 < 8 and 7 > 6? (a) True (b) False : ")
if q3.lower() == "a":
    print("Correct! 5 is less than 8 and 7 is greater than 6, so the result is True.")
    correct += 1
else:
    print("Incorrect. The correct answer is (a) True.")

# Question 4: The `else` Statement
q4 = question_with_response("4. When is the `else` block executed? (a) When the `if` condition is true (b) When the `if` condition is false (c) When the `elif` condition is true : ")
if q4.lower() == "b":
    print("Correct! The `else` block is executed when the `if` condition is false.")
    correct += 1
else:
    print("Incorrect. The correct answer is (b) When the `if` condition is false.")

# Question 5: Multiple Conditions
q5 = question_with_response("5. What does this statement do: if x > 10 and y < 5: (a) It checks if both x is greater than 10 and y is less than 5 (b) It checks if either x is greater than 10 or y is less than 5 (c) It will always return True : ")
if q5.lower() == "a":
    print("Correct! The `and` operator checks if both conditions are true.")
    correct += 1
else:
    print("Incorrect. The correct answer is (a) It checks if both x is greater than 10 and y is less than 5.")

# Display the final score
print(user_name + ", you scored " + str(correct) + "/" + str(questions))