Random

Guessing game

# Guessing game

# Description

# The computer will pick a number between 1 and 100. (You can choose any high number you want.) The purpose of the game is to guess the number the computer picked in as few guesses as possible.

# Input

# The user will enter his or her guess until the correct number is guessed.

# Output

# The program will keep asking the user to guess until he or she gets the number correct. Then the program will print how many guesses were required.

# Sample session

# Time to play a guessing game.

# Enter a number between 1 and 100: 62
# Too high. Try again: 32
# Too low. Try again: 51
# Too low. Try again: 56

# Congratulations! You got it in 4 guesses.

from random import randint
choice = randint(1,10)
print choice
for x in range(1,10):
  strin = raw_input('Enter your choice:')
  if int(choice) == int(strin):
    if x > 1:
      print 'you got it in ' + str(x) +' tries'
      break
    else:
      print 'you got it in first try'
      break  
  else:
    print 'Keep Trying'
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