fork download
  1. quiz_data = [
  2. {
  3. "question": "What does HTML stand for?",
  4. "options": ["A. Hyperlink Text Markup Language", "B. Hyper Transfer Markup Language", "C. Hypertext Markup Language", "D. High-Level Text Markup Language"],
  5. "answer": "C"
  6. },
  7. {
  8. "question": "Which programming language is often used for web development?",
  9. "options": ["A. Python", "B. Java", "C. Ruby", "D. JavaScript"],
  10. "answer": "D"
  11. },
  12. {
  13. "question": "What is the primary function of CSS in web development?",
  14. "options": ["A. Data storage", "B. Styling and layout", "C. Server-side scripting", "D. Database management"],
  15. "answer": "B"
  16. },
  17. {
  18. "question": "What does the acronym SQL stand for?",
  19. "options": ["A. Structured Query Language", "B. Simple Query Language", "C. Standard Query Language", "D. Sequential Query Language"],
  20. "answer": "A"
  21. },
  22. {
  23. "question": "Which programming language is often used for data analysis and scientific computing?",
  24. "options": ["A. JavaScript", "B. Java", "C. Python", "D. C++"],
  25. "answer": "C"
  26. },
  27. {
  28. "question": "What does API stand for in the context of web development?",
  29. "options": ["A. Application Programming Interface", "B. Advanced Programming Interface", "C. Automated Program Interaction", "D. All of the above"],
  30. "answer": "A"
  31. },
  32. {
  33. "question": "In Python, which keyword is used to define a function?",
  34. "options": ["A. define", "B. func", "C. def", "D. function"],
  35. "answer": "C"
  36. },
  37. {
  38. "question": "What is the output of the following code: `print(3 * 'Hello ')`?",
  39. "options": ["A. Hello Hello Hello Hello", "B. 9", "C. Hello Hello Hello", "D. Syntax Error"],
  40. "answer": "C"
  41. },
  42. {
  43. "question": "In JavaScript, how do you declare a variable?",
  44. "options": ["A. var", "B. variable", "C. let", "D. declare"],
  45. "answer": "A"
  46. },
  47. {
  48. "question": "Which data type in Python is used to represent a sequence of characters?",
  49. "options": ["A. int", "B. float", "C. str", "D. list"],
  50. "answer": "C"
  51. },
  52. {
  53. "question": "What is the primary purpose of version control systems like Git?",
  54. "options": ["A. To write code", "B. To run code", "C. To manage and track changes in code", "D. To execute code"],
  55. "answer": "C"
  56. },
  57. {
  58. "question": "What is the main advantage of object-oriented programming (OOP)?",
  59. "options": ["A. Simplicity", "B. Reusability", "C. Procedural nature", "D. No need for functions"],
  60. "answer": "B"
  61. },
  62. {
  63. "question": "What is the HTTP status code for a successful response?",
  64. "options": ["A. 200 OK", "B. 404 Not Found", "C. 500 Internal Server Error", "D. 302 Found"],
  65. "answer": "A"
  66. },
  67. {
  68. "question": "In Python, which library is commonly used for data visualization?",
  69. "options": ["A. NumPy", "B. Pandas", "C. Matplotlib", "D. TensorFlow"],
  70. "answer": "C"
  71. },
  72. {
  73. "question": "What is the purpose of a constructor method in object-oriented programming?",
  74. "options": ["A. To create objects", "B. To destroy objects", "C. To update objects", "D. To copy objects"],
  75. "answer": "A"
  76. },
  77. {
  78. "question": "Which of the following is not a valid Python data type?",
  79. "options": ["A. int", "B. double", "C. list", "D. tuple"],
  80. "answer": "B"
  81. },
  82. {
  83. "question": "What is the result of the following Python code: `3 + '3'`?",
  84. "options": ["A. 6", "B. '33'", "C. TypeError", "D. '6'"],
  85. "answer": "C"
  86. },
  87. {
  88. "question": "Which programming language is often used for developing mobile applications?",
  89. "options": ["A. Java", "B. Python", "C. C#", "D. PHP"],
  90. "answer": "A"
  91. },
  92. {
  93. "question": "What is the purpose of the `if` statement in programming?",
  94. "options": ["A. To perform a loop", "B. To declare a function", "C. To make decisions based on conditions", "D. To define a class"],
  95. "answer": "C"
  96. }
  97. ]
  98. def ask_question(question_data):
  99. print(question_data["question"])
  100. for option in question_data["options"]:
  101. print(option)
  102. user_answer = input("Enter your answer (A, B, C, D): ").upper()
  103. return user_answer == question_data["answer"]
  104.  
  105. score = 0
  106. total_questions = len(quiz_data)
  107.  
  108. for i, question in enumerate(quiz_data, start=1):
  109. print(f'Question {i} of {total_questions}')
  110. if ask_question(question):
  111. print("Correct!\n")
  112. score += 1
  113. else:
  114. print(f"Wrong! The correct answer is {question['answer']}.\n")
  115. print("Your score is", score)
  116.  
  117. print(f"Your total score is {score}/{total_questions}.")
  118.  
Success #stdin #stdout 0.03s 25628KB
stdin
Standard input is empty
stdout
quiz_data = [
    {
        "question": "What does HTML stand for?",
        "options": ["A. Hyperlink Text Markup Language", "B. Hyper Transfer Markup Language", "C. Hypertext Markup Language", "D. High-Level Text Markup Language"],
        "answer": "C"
    },
    {
        "question": "Which programming language is often used for web development?",
        "options": ["A. Python", "B. Java", "C. Ruby", "D. JavaScript"],
        "answer": "D"
    },
    {
        "question": "What is the primary function of CSS in web development?",
        "options": ["A. Data storage", "B. Styling and layout", "C. Server-side scripting", "D. Database management"],
        "answer": "B"
    },
    {
        "question": "What does the acronym SQL stand for?",
        "options": ["A. Structured Query Language", "B. Simple Query Language", "C. Standard Query Language", "D. Sequential Query Language"],
        "answer": "A"
    },
    {
        "question": "Which programming language is often used for data analysis and scientific computing?",
        "options": ["A. JavaScript", "B. Java", "C. Python", "D. C++"],
        "answer": "C"
    },
    {
        "question": "What does API stand for in the context of web development?",
        "options": ["A. Application Programming Interface", "B. Advanced Programming Interface", "C. Automated Program Interaction", "D. All of the above"],
        "answer": "A"
    },
    {
        "question": "In Python, which keyword is used to define a function?",
        "options": ["A. define", "B. func", "C. def", "D. function"],
        "answer": "C"
    },
    {
        "question": "What is the output of the following code: `print(3 * 'Hello ')`?",
        "options": ["A. Hello Hello Hello Hello", "B. 9", "C. Hello Hello Hello", "D. Syntax Error"],
        "answer": "C"
    },
    {
        "question": "In JavaScript, how do you declare a variable?",
        "options": ["A. var", "B. variable", "C. let", "D. declare"],
        "answer": "A"
    },
    {
        "question": "Which data type in Python is used to represent a sequence of characters?",
        "options": ["A. int", "B. float", "C. str", "D. list"],
        "answer": "C"
    },
    {
        "question": "What is the primary purpose of version control systems like Git?",
        "options": ["A. To write code", "B. To run code", "C. To manage and track changes in code", "D. To execute code"],
        "answer": "C"
    },
    {
        "question": "What is the main advantage of object-oriented programming (OOP)?",
        "options": ["A. Simplicity", "B. Reusability", "C. Procedural nature", "D. No need for functions"],
        "answer": "B"
    },
    {
        "question": "What is the HTTP status code for a successful response?",
        "options": ["A. 200 OK", "B. 404 Not Found", "C. 500 Internal Server Error", "D. 302 Found"],
        "answer": "A"
    },
    {
        "question": "In Python, which library is commonly used for data visualization?",
        "options": ["A. NumPy", "B. Pandas", "C. Matplotlib", "D. TensorFlow"],
        "answer": "C"
    },
    {
        "question": "What is the purpose of a constructor method in object-oriented programming?",
        "options": ["A. To create objects", "B. To destroy objects", "C. To update objects", "D. To copy objects"],
        "answer": "A"
    },
    {
        "question": "Which of the following is not a valid Python data type?",
        "options": ["A. int", "B. double", "C. list", "D. tuple"],
        "answer": "B"
    },
    {
        "question": "What is the result of the following Python code: `3 + '3'`?",
        "options": ["A. 6", "B. '33'", "C. TypeError", "D. '6'"],
        "answer": "C"
    },
    {
        "question": "Which programming language is often used for developing mobile applications?",
        "options": ["A. Java", "B. Python", "C. C#", "D. PHP"],
        "answer": "A"
    },
    {
        "question": "What is the purpose of the `if` statement in programming?",
        "options": ["A. To perform a loop", "B. To declare a function", "C. To make decisions based on conditions", "D. To define a class"],
        "answer": "C"
    }
]
def ask_question(question_data):
    print(question_data["question"])
    for option in question_data["options"]:
        print(option)
    user_answer = input("Enter your answer (A, B, C, D): ").upper()
    return user_answer == question_data["answer"]

score = 0
total_questions = len(quiz_data)

for i, question in enumerate(quiz_data, start=1):
    print(f'Question {i} of {total_questions}')
    if ask_question(question):
        print("Correct!\n")
        score += 1
    else:
        print(f"Wrong! The correct answer is {question['answer']}.\n")
    print("Your score is", score)

print(f"Your total score is {score}/{total_questions}.")