Я создавал простую игру-викторину, основанную на командной строке, в которой пользователь может выбрать вариант из заданного набора параметров и перейти к следующему вопросу. Для этого я использую библиотеку pyInquirer и список типов для того же.
Вот мой код:
from PyInquirer import style_from_dict, prompt,Token, Separator
style = style_from_dict({
Token.Separator : '#cc5454',
Token.QuestionMark : '#673ab7',
Token.Selected : '#cc5454',
Token.Pointer : '#673ab7 bold',
Token.Instruction : '',
Token.Answer : '#f44336 bold',
Token.Question : '#673ab7',
})
# this function will take users solution list and correct solutions list and return the score after matching elements of both the lists
def getScore(correct,user):
score = 0
for c,u in zip(correct,user):
if c == u:
score += 1
return score
correct_answers = ['Moscow','Yuan']
questions = [
{
'type' : 'list',
'name' : 'capital',
'message' : '\n what is capital of Russia ?',
'choices' : ['Moscow','Serbia','St pittsburgh']
},
{
'type' : 'list',
'name' : 'currency',
'message' : '\n what is currency of China ?',
'choices' : ['Yuan','Yen','Dollars']
}
]
# passing the above questions dictionary to prompt is responsible for printing questions and options on screen and selecting any one of them.
answers = prompt(questions,style = style)
# extracting options selected by the user from answers dictionary to match with correct solutions
user_answers = [j for j in answers.values()]
score = getScore(correct_answers,user_answers)
print('Your score :',score)
Все работает нормально, за исключением того, что вопросы не печатаются на экран. Вот скриншот кода, работающего в командной строке. На снимке экрана показано время, когда отображается вопрос 1 и соответствующие параметры.
Может кто-нибудь сказать мне, где моя ошибка, как ее исправить? , И если есть какой-либо способ заменить эти вопросительные знаки с экрана номерами вопросов
В этой игре также есть часть пользовательского интерфейса, которую я создал с помощью модуля pyfiglet, но я не думаю, что эта часть имеет какое-либо отношение к вышеуказанной проблеме