0
How to put in loop?
I have the code: guess = int(input()) if 1 <= guess <= 9: outcome = random.randint(1, 9) if guess == outcome: print("You are right, answer: ", outcome) else: print("Your guessed ", guess, ",sorry the answer is", outcome, " better luck next time") if guess != outcome: print("guess again") What should i do to give a loop to my code, i want to ask again and again for number, until the guess will be correct :)
3 odpowiedzi
+ 1
number = random.randint(1,10)
While True:
a= int(input("Number..."))
if a==number:
print("Well done")
break
else:
print("Try again")
0
import random
guess = int(input())
while True:
if 1 <= guess <= 9:
outcome = random.randint(1, 9)
if guess == outcome:
print("You are right, answer: ", outcome)
break
else:
print("Your guessed ", guess, ",sorry the answer is", outcome, " better luck next time")
if guess != outcome:
print("guess again")
0
import random
guess = int(input())
while True:
if 1 <= guess <= 9:
outcome = random.randint(1, 9)
if guess == outcome:
print("You are right, answer: ", outcome)
break
else:
print("Your guessed ", guess, ",sorry the answer is", outcome, " better luck next time")
if guess != outcome:
print("guess again")
Why i am always guessing the right answer? Is it anything wrong in this code? What should i change?