Register your child for In-person Robotics Workshop on 28th April at DC, Tracy, CA. Reserve a Seat today!

tect-corner-img

My Mysterious MCQ Quiz


Author: Lokesh
Category: General

My name is Lokesh i have created a mcq quiz on python IDLE I have put some random questions for you to try out on python IDLE

 

My name is Lokesh i have created a mcq quiz on python IDLE I have put some random questions for you to answer and you can put in ur own questions and change the answers.

Here is the code:

def new_game():

guesses = []
correct_guesses = 0
question_num = 1

for key in questions:
print(“————————-“)
print(key)
for i in options[question_num-1]:
print(i)
guess = input(“Enter (A, B, C, or D): “)
guess = guess.upper()
guesses.append(guess)

correct_guesses += check_answer(questions.get(key), guess)
question_num += 1

display_score(correct_guesses, guesses)

def check_answer(answer, guess):

if answer == guess:
print(“CORRECT!”)
return 1
else:
print(“WRONG!”)
return 0

def display_score(correct_guesses, guesses):
print(“————————-“)
print(“RESULTS”)
print(“————————-“)

print(“Answers: “, end=””)
for i in questions:
print(questions.get(i), end=” “)
print()

print(“Guesses: “, end=””)
for i in guesses:
print(i, end=” “)
print()

score = int((correct_guesses/len(questions))*100)
print(“Your score is: “+str(score)+”%”)

def play_again():

response = input(“Do you want to play again? (yes or no): “)
response = response.upper()

if response == “YES”:
return True
else:
return False

 

questions = {
“Who is Lokesh?: “: “A”,
“What is the best game?: “: “B”,
“What is 2+2?: “: “C”,
“Who is the best teacher?: “: “A”,

“Is the Earth round?: “: “A”
}

options = [[“A. a boy”, “B. a girl”, “C. a man”, “D. a woman”],
[“A. valorant”, “B. brawl stars”, “C. rocket league “, “D. fortnite “],
[“A. 1”, “B. 3”, “C. 4”, “D. 2”],
[“A. Akshay”, “B. Sharma”, “C. Prathvi”, “D. Altaf”],
[“A. True”,”B. False”, “C. maybe”, “D. What’s that?”]]

new_game()

while play_again():
new_game()

print(“See you again!”)

 

Here is the output:

————————-
Who is Lokesh?:
A. a boy
B. a girl
C. a man
D. a woman
Enter (A, B, C, or D): a
CORRECT!
————————-
What is the best game?:
A. valorant
B. brawl stars
C. rocket league
D. fortnite
Enter (A, B, C, or D): b
CORRECT!
————————-
What is 2+2?:
A. 1
B. 3
C. 4
D. 2
Enter (A, B, C, or D): c
CORRECT!
————————-
Who is the best teacher?:
A. Akshay
B. Sharma
C. Prathvi
D. Altaf
Enter (A, B, C, or D): d
WRONG!
————————-
Is the Earth round?:
A. True
B. False
C. maybe
D. What’s that?
Enter (A, B, C, or D): a
CORRECT!
————————-
RESULTS
————————-
Answers: A B C A A
Guesses: A B C D A
Your score is: 80%
Do you want to play again? (yes or no): no
See you again!

2 168

Comments (2)

Leave a comment