Game Update

Make sure you have already read my post “Super Duper Cool Game” before reading this post!

We have some other functions in this update:

  • Game restarting: You don’t have to run the program again when you want to play again.

  • Error finding: the program will make sure you entered a number.

  • Error finding 2: the program will make sure the minimum is not bigger than the maximum.

  • Big titles: a big title when you enter or restart the game.

The other rules are still the same. I will include the HTML game in another post to make it easier to play.

This code is not debugged by an AI. If I found any errors, I will republish it. If you do, pls comment.

Have fun :^)

import random

answer = random.randint(1, 100)

min_val = 1

max_val = 100

print(‘——–Number Bomb Game——–‘)

while True:

    try:

        enter = int(input(‘Pls enter your number between ‘ + str(min_val) + ‘ and ‘ + str(max_val) + ‘:’))

        if enter max_val:

            print(‘That number is illegal. Pls enter another one.’)

        if enter == answer:

            print(‘You have guess the bomb. Game over. You lose.’)

            enter = input(‘Enter “yes” to play again or enter anything else to exit:’)

            if not enter == ‘yes’:

                break

            answer = random.randint(1, 100)

            min_val = 1

            max_val = 100

            print(‘——–Number Bomb Game Restarting——–‘)

        else:

            if enter > answer:

                max_val = enter – 1

            else:

                min_val = enter + 1

            if min_val > max_val:

                print(‘——–Range error, restarting——–‘)

            robot_enter = random.randint(min_val, max_val)

            print(‘The robot had guessed’, robot_enter, ‘.’)

            if robot_enter == answer:

                print(‘The robot have guess the bomb. Game over. You won.’)

                enter = input(‘Enter “yes” to play again or enter anything else to exit:’)

                if not enter == ‘yes’:

                    break

                print(‘——–Number Bomb Game Restarting——–‘)

                answer = random.randint(1, 100)

                min_val = 1

                max_val = 100

            else:

                if robot_enter > answer:

                    max_val = robot_enter – 1

                else:

                    min_val = robot_enter + 1

    except ValueError:

        print(“That’s not an integer. Pls enter an integer.”)

Leave a Comment