3 Replies - 2272 Views - Last Post: 15 July 2012 - 08:20 PM

#1 rockstar_   User is offline

  • D.I.C Head
  • member icon

Reputation: 34
  • View blog
  • Posts: 189
  • Joined: 16-October 06

Numbers Guessing Game

Posted 23 October 2006 - 08:03 AM

Description: Just run it through the python interpreter, play the game, then look at the code.This is actually a very simple game I thought of constructing after answering a Python question in the forums. It demonstrates the use of a while loop. It also demonstrates a simple use of the random library
import random

number = random.randint( 1, 100 )
answer = ''
print 'I'm thinking of a number between 1 and 100'
print 'What is the number I'm thinking of?'
attempts = 0
while answer != number:
  attempts = attempts + 1
  answer = raw_input( '?' )
  answer = int( answer )
  if( answer > number ):
    print 'Lower'
  elif( answer < number ):
    print 'Higher'
  elif( answer == number ):
    print 'You got it in %i tries!' % (attempts)


Is This A Good Question/Topic? 0
  • +

Replies To: Numbers Guessing Game

#2 omochan   User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 148
  • Joined: 19-October 06

Re: Numbers Guessing Game

Posted 03 July 2008 - 12:44 PM

i did something similar to this. it's wonderful and you did a good job with this. good share ^^
Was This Post Helpful? 0
  • +
  • -

#3 atik97   User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: Numbers Guessing Game

Posted 15 December 2008 - 07:08 PM

good job done. thanks
Was This Post Helpful? 0
  • +
  • -

#4 k3y   User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 205
  • Joined: 25-February 12

Re: Numbers Guessing Game

Posted 15 July 2012 - 08:20 PM

Tahnks 4 influence: http://pastebin.com/0r2jsJGR
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1