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 :)

17th Sep 2020, 4:48 PM
Martyna Tomaszewska
Martyna Tomaszewska - avatar
3 Answers
+ 1
number = random.randint(1,10) While True: a= int(input("Number...")) if a==number: print("Well done") break else: print("Try again")
17th Sep 2020, 4:55 PM
Yahya Bey
Yahya Bey - avatar
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")
17th Sep 2020, 5:14 PM
Mohammad Aarif Ansari
Mohammad Aarif Ansari - avatar
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?
20th Sep 2020, 11:57 AM
Martyna Tomaszewska
Martyna Tomaszewska - avatar