Answer to Question #286091 in Python for ram

Question #286091

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 

output=100 

case=2 

input: A 

output=50 

case=3 

input=B 

output=0 




1
Expert's answer
2022-01-10T00:24:40-0500
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS