Â
In this we are going to see a basic program to create quiz using dictionary in Python Programming Language.
quiz = {
1: {
'question': 'What is the capital of India?',
'options': ['New Delhi', 'Mumbai', 'Chennai', 'Kolkata'],
'answer': 'New Delhi'
},
2: {
'question': 'No. of times India has won the world cup?',
'options': ['1', '2', '3', '4'],
'answer': '2'
},
3: {
'question': 'Who is the current president of India?',
'options': ['Narendra Modi', 'Rahul Gandhi', 'Sonia Gandhi', 'Manmohan Singh'],
'answer': 'Narendra Modi'
},
}
score = 0
print("Welcome to the quiz")
print("-----------------------------------------------------")
print("Let's Begin")
for i in range(1,len(quiz)+1):
print("Question ",i,": ",quiz[i]['question'])
print("-----------------------------------------------------")
for j in range(len(quiz[i]['options'])):
print(j+1,". ",quiz[i]['options'][j])
print("-----------------------------------------------------")
ans = int(input("Enter your answer: "))
if quiz[i]['answer'] == quiz[i]['options'][ans-1]:
print("Correct Answer")
score += 1
else:
print("Wrong Answer")
print("-----------------------------------------------------")
print("Your score is: ",score)
print("Thank You for playing")
# Coded By DHIRAJ SHELKE
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP