Guess

import random
numOfTries = 0
theNumber = int(random.random()*100)
print("Picked random number from 1 to 100")
print("Can you guess it?")
given = -1
while given != theNumber:
  given = input("If you want to stop give end:")
  if given == 'end':
    break
  given = -1
  while given < 0:
    given = input("Give number:")     
    given = int(given)
  numOfTries += 1     
  if theNumber > given:
    print("NO it's larger")
  elif theNumber < given:
    print("No it's smaller")
  else:
    print("You guessed it in %d guesses" % numOfTries)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s