Guess numbers based on the algorithm of the bisection method. By using the bisection method, you can filter out half of the numbers that may be wrong each time, which increases your guessing accuracy.
import randomnum = random.randint(1,100)count = 7print("The number guessing game starts! You have seven chances.")while True:guess = int(input("Input the number you think:"))if guess == num:print("You're right! Congradulations!")breakelif guess > num:count -= 1print("Smaller")print("You have", count, "chance(s)")elif guess < num:count -= 1print("Greater")print("You have", count, "chance(s)")if count == 0:print("Sorry! Game Over!")print("The number is",num)break
