Код: Выделить всё
Which one of these is a percussion instrument?
A. Trumpet
B. Euphonium
C. Viola
D. GlockenspielЯ умею открывать файлы, читать из них и отображать содержимое файла на экране, теперь я даже знаю, как рандомизировать информацию в файле. Однако, поскольку здесь задействовано несколько строк И еще один файл, из которого можно получить ответ, я понятия не имею, с чего начать.
Я был бы очень признателен за любую помощь, которую вы могли бы мне предложить.
Не стесняйтесь задавать вопросы, если вам нужно что-то прояснить.
РЕДАКТИРОВАТЬ:
Хорошо, я решил немного изменить свою идею, что может облегчить задачу. Использование файла CSV может быть лучшим вариантом. Вот что у меня есть на данный момент.
Код: Выделить всё
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()
Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/287 ... -text-file
Мобильная версия