dimanche 5 février 2017

Python random number game, response different based on closeness to random number

Attempting to generate different responses based on closeness of guess to the randomly generated number. Commented out sections are my attempts at generating a different response for a guess that is within 10 numbers of the random number.

import random

while True:

    number = random.randint(1,1000)
    guess = 0
    tries = 0

    while guess != number:
        guess = input('Please enter your guess, number must be between 0 and 1000: ')
        tries += 1
        if guess < number:
            print('Too Low!')
#       elif number - 10 <= guess:
#           print('Getting warm but still too low!')
        elif guess > number:
            print('Too High!')
#       elif number + 10 >= guess:
#           print('Getting warm but still too high!')
    print("Great Guess! The number was %i and you guessed it in %s tries!") % (number, tries)
    again = raw_input("Enter 'y' or 'n' to select to play again: ")
    if again == 'n':
        break




Aucun commentaire:

Enregistrer un commentaire