Ich habe versucht, eine Multiplikation Programm zu tun, wo nach einer falschen Antwort, wird es die Chance bekommen, versuchen Sie es erneut ein weiteres Mal.Python Multiplikation Programm Spiel, Nochmal versuchen Option
, dass mein Code:
from random import randint
wrong_answers = 0
for turn in range(100):
# Choose two random integers for the question to the player
factor_1 = randint(2,12)
factor_2 = randint(2,12)
# Precompute the correct answer to be able to check the player's answer
correct_answer = factor_1*factor_2
# As the question and get the player's response
question = 'What is ' + str(factor_1) + ' times ' + str(factor_2) + ' times ' + '?'
answer_string = raw_input(question)
#Convert the player's response to a number (raw_input yields a string)
answer_int = int(answer_string)
# See if the player's answer is correct or not, and proceed accordingly
if (answer_int == correct_answer):
print 'Correct!'
else:
print 'Wrong! Try Again!'
raw_input(question)
answer_int = int(answer_string)
if raw_input() == correct_answer:
print 'Correct'
else:
wrong_answers = wrong_answers + 1
if wrong_answers == 2:
print 'Game Over Thanks for playing!!!'
exit()
Das Problem ist, wenn wieder die Frage stellt, ist es nicht die richtige Antwort berechnen .. es wird es ignorieren und als falsche Antwort zählen. Nach der zweiten falschen Antwort endet das Programm.
Gibt es eine Möglichkeit, die Frage erneut zu machen, die richtige Antwort zählen und wenn die Person wieder die falsche Antwort bringt als Fehler zählt, und das Programm geht weiter?
Ich habe diesen Teil geändert, ich denke jetzt funktioniert es: sonst: drucken 'Falsch! Versuch es noch einmal!' answer_string = raw_input() antwort_int = int (antwort_zeichenfolge) wenn answer_int == richtige_ansendung: drucken 'Korrigieren'i diesen artikel geändert: –