我有這個問題,當我運行程序時,它一切都變好,但是當用戶得到正確的答案時,代碼不會打印既不打印(「好工作!」)或打印(「正確」)。代碼有什麼問題?我的python代碼不會在循環結束時運行打印語句
import random
firstNumber = random.randint(1, 50)
secondNumber = random.randint(1, 50)
result = firstNumber + secondNumber
result = int(result)
print("Hello ! What\'s your name ? ")
name = input()
print("Hello !"+" "+ name)
print("Ok !"+" "+ name +" "+ "let\'s start !")
print("What is"+ " " + str(firstNumber) +"+"+ str(secondNumber))
userAnswer = int(input("Your answer : "))
while (userAnswer != result) :
if (userAnswer > result) :
print("Wrong")
else:
print("Wrong")
userAnswer = int(input("Your answer : "))
if (userAnswer == result):
print("Correct")
print("Good Job!")
break
input("\n\n Press to exit")
這應該是被接受的答案。它清楚地解釋了問題並顯示瞭解決問題的方法。 – Insomniac