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.

    1. import random
    2. num = random.randint(1,100)
    3. count = 7
    4. print("The number guessing game starts! You have seven chances.")
    5. while True:
    6. guess = int(input("Input the number you think:"))
    7. if guess == num:
    8. print("You're right! Congradulations!")
    9. break
    10. elif guess > num:
    11. count -= 1
    12. print("Smaller")
    13. print("You have", count, "chance(s)")
    14. elif guess < num:
    15. count -= 1
    16. print("Greater")
    17. print("You have", count, "chance(s)")
    18. if count == 0:
    19. print("Sorry! Game Over!")
    20. print("The number is",num)
    21. break