how to make a number guessing game in python

Solutions on MaxInterview for how to make a number guessing game in python by the best coders in the world

showing results for - "how to make a number guessing game in python"
Lennart
20 Apr 2020
1# updated version
2import random
3# for instructions so that the user understands
4def instructions():
5    print("Welcome to the guessing game you will have 3 tries to pick a number 1-10")
6    print("Good luck btw it's all random")
7
8
9instructions()
10# guess limit so the user can't guess too much.
11guess_limit = 1
12# The random guess
13number = random.randint(1, 10)
14# What users can type and see.
15user = int(input("What is the number?: "))
16# The while loop so it can go on.
17while user != number:
18
19    if user > number:
20        print("Lower")
21
22    elif user < number:
23        print("Higher")
24
25    user = int(input("What is the number?: "))
26    guess_limit += 1
27    if guess_limit == 3:
28        print("------------------------------------------------------")
29        print("You ran out of guess ;( the answer was", number, "<--")
30        print("------------------------------------------------------")
31        break
32else:
33    print("You guessed it right! The number is", number,
34          "and it only took you ", guess_limit, "tries")
Zach
21 Sep 2017
1# importing random library
2# this game untill work untill u get  right answer
3import random
4a = 1
5rand = random.randint(1, 100)
6while 1 <= a:
7    a += 1
8    winin = int(input("enter a number under 100 : "))
9    if winin > 100:
10        print("not valid")
11        break
12    else:
13        if winin < rand:
14            print("too low")
15        elif winin > rand:
16            print("too high")
17        if winin == rand:
18            print(f"you got the right answer in {a - 1} times")
19            break 
20
Francoise
13 Aug 2016
1import random
2import os
3
4os.system('cls') # Enter CLS if You're on Windows, or CLR instead of CLS if You're on MacOS or Linux
5
6print("Welcome to Guess The Number.")
7
8number_range = int(input("Please Enter a Number to Guess Between > "))
9tries = int(input("Please Enter How Many Tries You'd Like. > "))
10number = random.randint(0, number_range)
11guessed = False
12lost = False
13
14tried = 0
15
16while guessed == False and lost == False:
17    os.system('cls') 
18    guess = int(input("Try and Guess The Number. > "))
19    os.system('cls')
20    if guess > number:
21        print("Too High! Try to Go Lower.")
22        input()
23    elif guess < number:
24        print("Too Low! Try to Go Higher.")
25        input()
26    elif guess == number:
27        print("You Guessed The Number! You Won!")
28        input()
29        guessed = True
30    tried += 1
31    if tried == tries:
32      os.system('cls')
33      print(f"Aww. You Ran out of Tries. {number} was The Answer.")
34      lost = True
35
36if lost == False:
37    os.system('cls')
38    print("Congratulations! You Won Guess The Number.")
39
40if lost == False:
41    print("Congratulations! You Won Guess The Number.")
42
queries leading to this page
create a number guessing game using pythonguess a number in pythonguess random number pythonnumber guessing game python codenumber game in pythonnumber guessing using pythonrandom number game pythonpython number guessing game for beginnersguessing number game pythonnumber guessing pythonhow to make a time guessing in pythonpython guess game number guessing game pythonguess an integer number in a range in python algorithmguess the number pythonstarting out with python random number guessing gamepython number guessing game sourcehow to make a number guessing game in pythonnumber guessing game code pythonnumber guessing python gamecreate a number guessing game in pythonguessing game python examplepython number guessing gamehow to make a python guessing gameguessing game code pythonhow to make an number guessing game in python begniarsnumber guessing game python algorithmguessing the number game in pythonpython guesing gameguess the number game pythonpython number guessing game scriptguessing game in pythonhow to make code in python for guessing gamehow to make a number guesser game in pythonhow to make a random number guessing game in pythonrandom guess game pythonpython how to make a number guessing gamehow to make a simple guessing game in pythonpython guessing gamenumber guessing in pythonguess the number python codeeasy guessing game in pythonpython for beginners guessing gamesimple number guess game pythonguessing game with pythonguessing games in pythonhow to make a guessing game in python 3how to make a random number guesser in pythonnumber guessing game in pythonguessing game with random pythonpython guess random numberpython number guessing game codeunderstanding a guessing game in pythonguessing game in python code with functionspython code for number guessing gamepython guessing number gamepython program to guess a numberhow to code a number guessing game in pythonhow to make number guessing game in pythonsimple python guessing game codehow to create a guessing game in pythonpython random number gamehow to do a guessing game on pythonpython3 guessing gamepython number guessingpython simple quessing gamegenerate a random number between 1 and 25 28including 1 and 25 29 ask the user to guess the number 2c and then tell them whether they guessed too low 2c too high 2c or exactly right the program should execute until user find exactly right number guessing game pythonpython number guessing game tutorial use of guessing the number game in pythoncomputer generates 4 numbers 2c user guesses numbers 2c in pythonnumber geussing project pythonguess game pythonbuild a number guessing game using pythonhow to make guessing game in pythonhow to make a guessing game in pythonguessing user number input pythonpython simple guessing gameguessing game python codehow to make a number guessing game in python