guess the number python

Solutions on MaxInterview for guess the number python by the best coders in the world

showing results for - "guess the number python"
Riccardo
03 Oct 2016
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")
Camila
30 Jan 2018
1import random
2print('Hi! What is your name?')
3name= input()
4print('Well ' + str(name) + ', I was thinking of a random number between 1 and 15. Can you guess that number? If you are interested: ')
5
6computerNumber= random.randint(1, 15)
7
8for guessedNumber in range(1, 7):
9    print('Please guess a number.')
10    guess= input()
11    if int(guess) < computerNumber:
12        print('The number is too low.')
13    elif int(guess) > computerNumber:
14        print('The number is too high.')
15    else:
16        break # If the guess is correct.
17if int(guess) == computerNumber:
18    print('Great job, ' + str(name) + '! You made the right guess.')
19    print('You guessed my number in ' + str(guessedNumber) + ' guesses.')
20else:
21    print('Nope! The number I was thinking of was ' + str(computerNumber) + '.')
22
queries leading to this page
python number guessing game sourceguess number program in pythonguess a number in pythonguessing the number game in pythonpython guess the number gamenumber guessing using pythonnumber game in pythoncomputer generates 4 numbers 2c user guesses numbers 2c in pythongenerate 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 number guess game pythonmake guess the number pythonpython number guessing game scriptguess number game in pythonnumber guessing python gamehow to make code in python for guessing gamehow to make a number guesser game in pythonhow to make number guessing game in pythonwrite a program guess the number game pythonsimple number guess game pythonguess my number game pythonpython guess numbers use of guessing the number game in pythonpython guess the numberstarting out with python random number guessing gamepython number guessing game for beginnerspython guess numbeeasy guessing game in pythonhow to make a guessing game in python 3how to make a time guessing in pythonsimple python guessing game codepython game programming guess numberhow to make a python guessing gameguess random number python with functionsguessing game with pythonguessing game code pythonnumber guesser pythonguessing games in pythonguess a four digit number pythoncreate a number guessing game using python guess a number game using pythonpython number guessinghow to make a number guessing game in pythonguess the number game pythonguess my number python codepython how to make a number guessing gamenumber geussing project pythonguess random number pythonhow to create a guessing game in pythonunderstanding a guessing game in pythonpython number guessing game codeguessing game pythonhow to make a random number guessing game in pythonguess an integer number in a range in python algorithmpython random number gamenumber guessing pythonnumber guessing game python algorithmpython number guessercreate a number guessing game in pythonguess number pythonpython simple guessing gamepython number guessing gameguessing game python codepython algorithm for guess a number codenumber guesser python codepython guesing gameguess game pythonpython3 guessing gamepython programming tutorial guess numbernumber guessing game pythonguessing game python examplehow to make a guessing game in pythonpython guess random numberrandom number game pythonpython for beginners guessing gamehow to make guessing game in pythonhow to code a number guessing game in pythonnumber guessing game python codehow to do a guessing game on pythoncode that guesses a number pythonnumber guessing in pythonpython program to guess a numberpython guessing gamepython guess game simple number guesser in pythonguess a number game using python random guess number pythonpython simple quessing gameguessing game in pythonhow to make guess the number game in pythonpython number guesser codenumber guessing game in pythonguessing number game pythonhow to make the computer guess a number in pythonpython guessing number gameguessing user number input pythonbuild a number guessing game using pythonguess the number python codeguessing game in python code with functionspython number guessing game tutorialhow to make a guess the number game in pythonguessing game with random pythonhow to make a random number guesser in pythonrandom guess game pythonnumber guessing game code pythonguess the number using pythonhow to make a program to guess a number pythonpython code for number guessing gameguess the number pythonhow to make a simple guessing game in pythonguess the number python