n=input("Guess")
i=1;
if int(n)==9:
print("You win")
else:
while int(n)!=9 and i<3:
n=input("Guess")
i+=1
if int(n)==9:
print("you win")
if i==3 and n!=9:
print("Fail")
First I input 7 , then 8 and in the end 9 (so 'n' becomes 9) But still, Fail gets printed!
The command below should not run since 'n' is equal to 9
if i==3 and n!=9:
print("Fail")
I guess this is what you need in a cleaner approach. You should check if the input is really an int, which is not included here:
i = 0
while i < 3:
n = int(input("Guess"))
i += 1
if n == 9:
break
if n == 9:
print("you win")
else:
print("Fail")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.