Write a python program to generate a quiz using two files, named Questions.txt and Answers.txt. The program opens Questions.txt and displays the question with options on the screen. The program will verify the Answer.txt file and display the scores.
For example, Questions.txt file contains the following details:
1. Who is the prime minister of India?
A. Narendra Modi B. Shivraj Patil
2. Who is the President of USA?
A. Donald Trump B. Joe Biden
Answer.txt file contains the following details:
1.A
2.B
If inputs are A and B, then the Score is 100
case=1
input= A
B
output=100
case=2
input: A
A
output=50
case=3
input=B
A
output=0
Questions = open("H:\\Questions.txt","r")
Answers = open("H:\\Answer.txt","r")
Q = (Questions.read()).split("\n")
A = (Answers.read()).split("\n")
print(len(Q))
Questions.close()
Answers.close()
print(A)
ans=[]
for r in range(0,len(A)):
ans.append(A[r][-1])
Res=[]
Score=0
c=0
for r in range(0,len(Q),2):
print("\n",Q[r])
print("\t",Q[r+1])
Flag=1
while(Flag):
Res = (str(input("Enter Answer (A/B/C/D): "))).lower()
if(Res=="a" or Res=="b" or Res=="c" or Res=="d"):
Flag=0
if(Res==ans[c].lower()):
Score = Score+50
c=c+1
print("\nFinal Score = ",Score)
Comments
Leave a comment