Skip to main content
deleted 74 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

ImI'm not really even sure if this counts as a game... There is so little code that I'm not even sure I should post it here... But, but it works, and is done, so... It is a game where you have to guess the computers number, and it tells you how many times you took to get it right. I kind of want feedback, and not ways to improve the code... I want to know ways to improve my futrefuture projects and what to avoid again.

Im not really even sure if this counts as a game... There is so little code that I'm not even sure I should post it here... But it works, and is done, so... It is a game where you have to guess the computers number, and it tells you how many times you took to get it right. I kind of want feedback, and not ways to improve the code... I want to know ways to improve my futre projects and what to avoid again.

I'm not really even sure if this counts as a game. There is so little code, but it works. It is a game where you have to guess the computers number, and it tells you how many times you took to get it right. I kind of want feedback, and not ways to improve the code. I want to know ways to improve my future projects and what to avoid again.

edited tags; edited title
Link
200_success
  • 145.6k
  • 22
  • 191
  • 481

Guessing Game Python Number-guessing game

Source Link

Guessing Game Python

Im not really even sure if this counts as a game... There is so little code that I'm not even sure I should post it here... But it works, and is done, so... It is a game where you have to guess the computers number, and it tells you how many times you took to get it right. I kind of want feedback, and not ways to improve the code... I want to know ways to improve my futre projects and what to avoid again.

def main():
    # Guess My Number
    #
    # The computer picks a random number between 1 and 100
    # The player tries to guess it and the computer lets
    # the player know if the guess is too high, too low
    # or right on the money

    import random  

    def ask_number(question, low, high, step):
        response = None
        while response not in range(low, high):
            response = int(input(question))
        return response
        tries += step
        

    #Opening Remarks
    print("Welcome to 'Guess My Number'!")
    print("I'm thinking of a number between 1 and 100.")
    print("Try to guess it in as few attempts as possible.")

    # set the initial values
    the_number = random.randint(1, 100)
    # Create the priming read here
    tries = 0
    guess= 0
    while int(guess) != int(the_number):

        guess = ask_number("Enter your guess:", 1, 100, 1)

        if int(guess) == int(the_number):
            print("Your right on the money!")
        elif int(guess) > int(the_number):
            print("To high!")
        elif int(guess) < int(the_number):
            print("To low!")

        tries += 1
    #Didnt know how to make it reloop to the start...
    print("You guessed it!  The number was", the_number)
    print("And it only took you", tries, "tries!")

    #Program Closing  
    input("Press the enter key to exit.")

main()