def guessgame(guess, n): if guess == n: return 0 elif guess < n: return -1 else: return 1 import random as r n = r.randint(0,100) counter = 0 guessed = False while (guessed == False): guess = int(input("What number did I think of?:")) counter += 1 result = guessgame(guess, n) if result == 0: guessed = True elif result == -1: print("Too low") else: print("Too high") print("Good guess! The number is", n, " You tried", counter, "times") import math print("Now you think of a number between 0 and 100!") upper = 100 lower = 0 answer ="" while answer != "good": guess = lower + math.floor((upper - lower)/2) print("Is it", guess, "? (high/low/good):") answer = input() if answer == "high": upper = guess elif answer == "low": lower = guess else: print("I made it!!! The number is", guess) |

Silver Announcements >