dimanche 21 janvier 2018

Update bounds of random number

I have the code below. Everything works except it does not update the upper and lower bounds for the random number.

import random

def main():

smaller = int(input("Enter the smaller number in range: "))
larger = int(input("Enter the larger number in range: "))
secretNum = int(input("Now think of a number between {} and {}: ".format(smaller, larger)))
input("Press enter to continue")   

count = 0
while True:
    count +=1
    computerGuess = random.randint(smaller, larger)        
    print("Is your number {}".format(computerGuess) + "?")
    userResponse = str(input("Enter =, < or >: "))

    if userResponse == '>':
        smaller == computerGuess + 1
    elif userResponse == '<':
        larger == computerGuess - 1
    elif userResponse == '=':
        print("I've got it in {} tries!".format(count))
        break




Aucun commentaire:

Enregistrer un commentaire