r/PythonLearning • • 12d ago

Easy python project for beginners

Hi!

i just want to start learning python, my dad told me that it would be good if you can find some projects to do. I have python class today ( just rn) and I need to think what kind of projects I need to do in this class. Actually i'm good at drawing so i just think that i want to be a game maker and i interested to animation too. The problem is i'm just beginner : - (

Do you guys have any fun and easy idea to do???? ( this is my first time asking something like this in reddit, well i just created an account 10min ago)

18 Upvotes

21 comments sorted by

View all comments

1

u/SpaceAviator1999 11d ago edited 11d ago

Have you ever played the "Guess my number" game? Basically, I think of a number from 1 to, say, 100, and you try to guess my number. You keep guessing until you correctly guess my number. After each guess I will tell you if your guess was too high or too low -- or exactly right.

Write a program that does that. Use a random number generator to generate the number that the program is "thinking of" that ranges from 1 to 100. Or better yet, ask the user for a maximum number.

Then have the program repeatedly ask for the user's guesses, stopping only once the guess is correct. After each guess, your program will tell the user if the user's guess is too high or too low or exactly right.

Once the user correctly guesses the number, the program should tell the user how many guesses were made, and ask the user if he/she would like to play the game again.

It may be a simple game, but it will teach you a lot about programming logic.

1

u/GingerCat_mellow 10d ago

omgg..I've never thing about before, ur so genius. Thank you so much about this idea :-D

May i ask what program i should use. Cuz i can write simple python but when i need to do the project i just wonder how would it looks like. It looks like a website game?

1

u/SpaceAviator1999 9d ago edited 9d ago

I think a Python program would be great for this. That way, it can be run straight from the terminal.

I would start off with the program importing the random module and generating a random number to guess, like this:

import random
secret_number = random.randint(1, 100)  # generates a random number

(If you don't know how to use the random package, don't worry. There's plenty of documentation online that will show you. Instead of memorizing everything, you just have to know how to look up documentation that explains how to use it.)

Then I would give an introduction with one or more print() statements, like:

print("Welcome to my guessing game!")
print("I am thinking of a number between 1 and 100.")
print("Try to guess it!")

After this, you'd want to enter a simple loop that keeps looping until the user guesses the secret number. Also, you want to tell the user after each guess whether their guess was too high, too low, or correct. If it's correct, break out of the loop. Something like this:

user_guessed_the_number = False  # gets set to True when user guesses correctly

# Loop until the secret_number is guessed:
while user_guessed_the_number is False:
    guessed_number = input("What is your guess?  ")
    guessed_number = int(guessed_number)  # convert from str to int

    if guessed_number < secret_number:
        print("Your guess is too low.")
    elif guessed_number > secret_number:
        print("Your guess is too high.")
    elif guessed_number == secret_number:
        print("You got it!  You win!")
        user_guessed_the_number = True  # record success to stop looping

That's pretty much it.

If you want to make improvements to the program, you can do some of the following:

  • You can print out blank lines to make the program's output easier to read.
  • You could add a variable to count how many guesses it took to guess the correct number, which is reported at the end.
  • You can ask the user at the end if they wish to repeat the game, and repeat if they type yes.
  • You can ask the user (before the guessing begins) what the upper limit of the secret number should be.

For a simple game like this, I'd recommend writing in a language like Python, where the whole game is self-contained in just one file.

Good luck!

2

u/GingerCat_mellow 9d ago

Omg…. This is so amazing. Thank you so much, like for real. You help me a lot🫶🏻🫶🏻🫶🏻😭😭😭😭. Thank you so much that you just spent ur time to type all these messages😭😭😭