這是我的代碼,但正如標題所說,我不能打破,而打破,如果我把東西了,而在外面真和生命去低於0沒有任何反應。Python將不會從真正
from random import randint
import sys
value = int(randint(1,10))
lives = int(5)
userinp = int(0)
if lives == 0:
print("no lives :(")
while True:
if lives != 0:
print(value)
print("You currently have: ", lives, " lives left")
userinp = input("Please enter a number from 1 to 10: ")
if int(userinp) == int(value):
print("Well done you wn :D")
sys.exit()
elif int(userinp) > int(value):
print("Your guess was too high please guess again")
lives = lives - 1
elif int(userinp) < int(value):
print("Your guess was too low please guess again")
lives = lives - 1
if lives == 0:
print("this")
哪裏*是*你的'break'? – elslooo
'lives = int(5); userinp = int(0)'爲什麼? – DeepSpace
「while True」是一個無限循環,佔用所有CPU週期的100%,並且永遠不會中斷 - 因爲只有當條件變爲False時,纔會結束'',但永遠不會,因爲它始終是' TRUE'! –