guessing game in python using while loop

Solutions on MaxInterview for guessing game in python using while loop by the best coders in the world

showing results for - "guessing game in python using while loop"
Timeo
25 Sep 2018
1import random
2# These are the two limits to make the game interesting...
3upper_limit = random.randint(0, 50)
4lower_limit = random.randint(50, 100)
5# This is the answer... It has to be outside the while loop or else it will keep on changing thus making the game weird.
6answer = random.randint(upper_limit, lower_limit)
7# The loop of the game to allow trials after failure and break when the gamer gueses correctly
8while True:
9    guess = int(input("Guess a number: "))
10    if guess == answer:
11        print(" Amazing")
12        break
13    if guess > answer:
14        print(" Too High")
15    if guess < answer:
16        print(" Too Low")
17
18