Week 14 Random numbers and binary search

posted Feb 2, 2017, 7:58 AM by Attila Lengyel
import random
print(random.uniform(0,100))
print(random.randint(0,100))
print(random.randint(1,6))

print("I thought of a number.")
number = random.randint(0,100)
counter = 0
while(True):
  guess = int(input("Try to guess:"))
  counter += 1
  if guess == number:
    print("What a chance? You nailed it!")
    print("It took you", counter, "guesses")
    break
  elif guess < number:
    print("It is less than what I thought of")
  else:
    print("It is greater than what I thought of")
  if counter == 7:
    print("You do not have the right strategy!")
    print("   +---+ ")
    print("   |   |")
    print("   O   |")
    print("  /|\  |")
    print("  / \  |")
    print("       | ")
    print("=========")
    break
  
Comments