-1
在猜出正確之後,似乎無法打印出「恭喜,您是正確的」。Python-無法打印您贏得
從隨機導入randintguessesTaken = 0
randomNumber = [STR(randint(1,9))爲_在範圍(4)]#創建隨機NUMS的列表
而
guessesTaken < 10:
guesses = list(input("Guess Number: ")) # create list of four digits
check = "".join([b if a==b else "H" if int(a)>int(b) else "L" for a, b in zip(guesses,randomNumber)])
if all(c == 'Y' for c in check): # if check has four Y's we have a correct guess
print("Congratulations, you are correct, it took you", guessesTaken, "guesses.")
break
else:
guessesTaken += 1 # else increment guess count and ask again
print(check)
if guessesTaken == 10:
print("You lose")
'check == randomNumber' ** not ** test *「if check has four Y's」* * – jonrsharpe 2014-10-26 18:11:12