#!/usr/bin/python3 #Number guessing game -- plain text version for TTY output. import random def playGame(maxnum): number = random.randrange(1,maxnum+1) #generate random number [1,maxnum] print('=====================================================') print('I am thinking of a number between 1 and ' + str(maxnum) + ' inclusive...') print('Try to guess my number in as few moves as possible.') moves = 0 guess = -1 while guess != number: print('Enter your guess (or q to quit)...') inp = input().strip(); if inp == 'q': quit() try: guess = int(inp) except: print('Please enter a valid integer!') continue moves+=1 #update moves counter on the screen print('MOVES: ' + str(moves)) if guess < number: #too low print(str(guess) + ' is too low!') elif guess > number: #too high print(str(guess) + ' is too high!') #user guessed it... print('You guessed it in ' + str(moves) + ' moves.') #print victory message input() #MAIN------------ #first prompt user to select difficulty level (number range): #easy = [1, 100], medium = [1,1000], hard = [1,10000] print('NEW GAME\nSelect difficulty level...') print('1. Easy') print('2. Medium') print('3. Hard') response = int(input().strip()) if response == 1: maxnum = 100 elif response == 2: maxnum = 1000 elif response == 3: maxnum = 10000 playGame(maxnum)