Hello everyone! Today I bring you a very simple game/challenge perfect for those that are new to Python! It’s called Guess The Number. You can play two it ways:
Multi player - Player One picks the number and Player Two tries to guess it.
Single Player - The program generates a random number and you try to guess it.
The statements above pretty much explain what you’ll be doing.
Don’t think to big, 15 / 20 lines of code should do it and it should take about 5 mins, 10 tops.
I’ll post my own code below. I chose to do it as a Multi Player. Feel free to post your code in any other language on the comments!
import random print "#------------------#" print "| GUESS THE NUMBER |" print "#------------------#" print '\n' number = raw_input('Pick your number > ') for i in range(0,15): print '\n' while True: guess = raw_input('Guess the number > ') if guess > number: print '\nHmmm, try a lower number...\n' elif guess < number: print '\nGo a little higher\n' else: print "Right on! Well done!" break