Мне нужна помощь с моим кодом, который продолжает давать мне эту ошибку. Ошибка:Код с ошибкой значения
ValueError: too many values to unpack (expected 2)
линия, которая дала мне ошибку эта линия:
question , answer = generateQuestions (maxNum)
Я не могу понять, как это исправить. Ниже мой код:
import random
def generateQuestions (maxNum) :
ops = ['+','-']
var1 = random.randrange (maxNum)
var2 = random.randrange (maxNum)
maxNum += 1
operation = random.choice (ops)
ques = 'What is' + str(var1) + operation + str(var2) + '?'
if operation == '+' :
var1 + var2
else :
var1 - var2
return ques
difficulty = 0
lives = 0
numofquestion = 0
correctCount = 0
while int (difficulty) <= int (0) or int(difficulty) >= int(4) :
print ('Welcome to the Math Tester')
print ('Please choose your difficulty')
difficulty = int (input ('"1" for Easy \n"2" for Medium \n"3" for Hard\n'))
if difficulty == 1 :
print ('Easy Selected, You Have 3 Lives')
lives , maxNum = 3,10
elif difficulty == 2 :
print ('Medium Selected, You Have 2 Lives')
lives , maxNum = 2,25
elif difficulty == 3 :
print ('Hard Selected, You Have 1 Life')
lives , maxNum = 1,50
for numofquestion in range (10) :
print ('Question', numofquestion + 1, 'of 10,',lives ,'lives remaining.')
question , answer = generateQuestions (maxNum)
print (question)
userAns = int (input())
if answer == userAns :
print ('Correct!')
correctCount += 1
else :
print ('Incorrect!')
lives -= 1
print ('Result :')
print ('You scored {}/10.'.format (correctCount))
print ('{} % - You {}!' .format ((correctCount/10)*100, 'pass' if correctCount > 4 else 'fail'))
Как я упоминал в своем ответе, лучше не давать реальных решений вопросов, связанных с домашним заданием. –
Спасибо за информацию. Извините за проблемы, которые у меня есть с моей домашней работой. –