Quizprogramm mit einer TextdateiPython

Python-Programme
Anonymous
 Quizprogramm mit einer Textdatei

Post by Anonymous »

versuche, in Python ein Quizprogramm zu erstellen, bei dem die Fragen in einer TXT -Datei mit den Antworten in einer anderen gespeichert werden. Die Fragen werden in der Textdatei wie folgt dargelegt: < /p>
Which one of these is a percussion instrument?
A. Trumpet
B. Euphonium
C. Viola
D. Glockenspiel
< /code>
Das Programm stellt die Fragen in zufälliger Reihenfolge aus und bewertet die Anzahl der richtigen Antworten. Da es jedoch mehrere Zeilen und eine andere Datei gibt, die die Antwort erhalten, habe ich keine Ahnung, wo ich anfangen soll. Die Verwendung einer CSV -Datei ist möglicherweise die bessere Option. Hier ist was ich bisher habe. < /P>
def Trivia():
score=0
myFile = open("farming.csv","r") # opens the CSV file and stores it in the array myFile
players = myFile.readlines() # reads the lines of the CSV file into the variable players
questionno=1
while questionno < 6:

for p in players:
data = p.split(",") #splits each cell of the CSV file into its parts
questions = data[0]
answera = data[1]
answerb = data[2]
answerc = data[3]
CorrectAnswer = data[4]
print("Question #",questionno)
print(questions) #prints the question and the 3 answers
time.sleep(0.5)
print(answera)
time.sleep(0.5)
print(answerb)
time.sleep(0.5)
print(answerc)
time.sleep(0.5)
answer = input("Answer? ") #asks the user for their answer
time.sleep(1)
print(".")
time.sleep(1)
print(".")
time.sleep(1)
print(".")

if answer == CorrectAnswer: #checks if the answer is correct and prints approptiate responses
print("That is the correct answer")
score=score+1
time.sleep(1)
else:
print("That is not the correct answer")
time.sleep(1)
print("Your current score is", score)
print("")
questionno = questionno+1

myFile.close()
< /code>
Mein Problem ist jetzt, dass ich nicht weiß, wie ich zur nächsten Frage im Quiz kommen soll. Mit diesem Format stellt es immer wieder die gleiche Frage. Irgendeine Idee?>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post