Created
June 25, 2025 09:52
-
-
Save shinysu/c891bfd103d07bbfd4d6b2e2520f79b5 to your computer and use it in GitHub Desktop.
quiz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# basic quiz app - one question | |
print("Welcome to the Quiz App!") | |
print("Please answer the following questions:") | |
print("1. What is the capital of India?") | |
answer = input("Your answer: ").strip().lower() | |
if answer == "new delhi": | |
print("Correct!") | |
else: | |
print("Incorrect! The correct answer is New Delhi.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# multiple questions | |
print("Welcome to the Quiz App!") | |
print("Please answer the following questions:") | |
print("1. What is the capital of India?") | |
answer = input("Your answer: ").strip().lower() | |
if answer == "new delhi": | |
print("Correct!") | |
else: | |
print("Incorrect! The correct answer is New Delhi.") | |
print("2. What is the largest planet in our solar system?") | |
answer = input("Your answer: ").strip().lower() | |
if answer == "jupiter": | |
print("Correct!") | |
else: | |
print("Incorrect! The correct answer is Jupiter.") | |
print("3. Who wrote 'Romeo and Juliet'?") | |
answer = input("Your answer: ").strip().lower() | |
if answer == "william shakespeare": | |
print("Correct!") | |
else: | |
print("Incorrect! The correct answer is William Shakespeare.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# using lists for questions and answers | |
questions = ["What is the capital of India?", | |
"What is the largest planet in our solar system?", | |
"Who wrote 'Romeo and Juliet'?"] | |
answers = ["new delhi", "jupiter", "william shakespeare"] | |
print("Welcome to the Quiz App!") | |
print("Please answer the following questions:") | |
for i in range(len(questions)): | |
print(f"{i + 1}. {questions[i]}") | |
answer = input("Your answer: ").strip().lower() | |
if answer == answers[i]: | |
print("Correct!") | |
else: | |
print(f"Incorrect! The correct answer is {answers[i].title()}.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# using lists for questions and answers | |
questions = { | |
"What is the capital of India?": "new delhi", | |
"What is the largest planet in our solar system?": "jupiter", | |
"Who wrote 'Romeo and Juliet'?": "william shakespeare" | |
} | |
print("Welcome to the Quiz App!") | |
print("Please answer the following questions:") | |
for question, answer in questions.items(): | |
print(question) | |
user_answer = input("Your answer: ").strip().lower() | |
if user_answer == answer: | |
print("Correct!") | |
else: | |
print(f"Incorrect! The correct answer is {answer.title()}.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# using lists for questions and answers | |
questions = { | |
"What is the capital of India?": ["New Delhi", "Chennai", "Bangalore", "new delhi"], | |
"What is the largest planet in our solar system?": ["Saturn", "Mars", "Jupiter", "jupiter"], | |
"Who wrote 'Romeo and Juliet'?": ["William Shakespeare", "Charles Dickens", "Mark Twain", "william shakespeare"] | |
} | |
print("Welcome to the Quiz App!") | |
print("Please answer the following questions:") | |
for question, options in questions.items(): | |
print("\n", question) | |
for i, option in enumerate(options[:-1], start=1): | |
print(f"{i}. {option}") | |
answer = options[-1].strip().lower() # The last option is the correct | |
user_answer = input("Your answer: ").strip().lower() | |
if user_answer == answer: | |
print("Correct!") | |
else: | |
print(f"Incorrect! The correct answer is {answer.title()}.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# using lists for questions and answers | |
questions = { | |
"What is the capital of India?": ["New Delhi", "Chennai", "Bangalore", "new delhi"], | |
"What is the largest planet in our solar system?": ["Saturn", "Mars", "Jupiter", "jupiter"], | |
"Who wrote 'Romeo and Juliet'?": ["William Shakespeare", "Charles Dickens", "Mark Twain", "william shakespeare"] | |
} | |
score = 0 | |
print("Welcome to the Quiz App!") | |
print("Please answer the following questions:") | |
for question, options in questions.items(): | |
print("\n", question) | |
for i, option in enumerate(options[:-1], start=1): | |
print(f"{i}. {option}") | |
answer = options[-1].strip().lower() # The last option is the correct | |
user_answer = input("Your answer: ").strip().lower() | |
if user_answer == answer: | |
score += 1 | |
print("Correct!") | |
else: | |
print(f"Incorrect! The correct answer is {answer.title()}.") | |
print(f"\nYour total score is {score} out of {len(questions)}.") | |
print("Thank you for participating in the quiz!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# using lists for questions and answers | |
score = 0 | |
print("Welcome to the Quiz App!") | |
print("Please answer the following questions:") | |
def read_questions(file_path): | |
questions = {} | |
with open(file_path, 'r') as file: | |
for line in file: | |
parts = line.strip().split(',') | |
question = parts[0] | |
options = parts[1:] | |
questions[question] = options | |
return questions | |
questions = read_questions('questions.csv') | |
print(questions) | |
for question, options in questions.items(): | |
print("\n", question) | |
for i, option in enumerate(options[:-1], start=1): | |
print(f"{i}. {option}") | |
answer = options[-1].strip().lower() # The last option is the correct | |
user_answer = input("Your answer: ").strip().lower() | |
if user_answer == answer: | |
score += 1 | |
print("Correct!") | |
else: | |
print(f"Incorrect! The correct answer is {answer.title()}.") | |
print(f"\nYour total score is {score} out of {len(questions)}.") | |
print("Thank you for participating in the quiz!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment