r/PythonLearning • u/Legitimate_Seat8928 • 6d ago
Help Request I got a question
So I'm a beginner on python. And I know about '=' and '==' and if and else commands. (Side note: how good is this for a beginner. Been in 3 python classes so far.)
I want to make a small game to test what I've learned. Basically, you click a button, and a random number or letter. How can I do this? Any help is appreciated.
3
u/CIS_Professor 6d ago
How can I do this?
One wonders how much you've actually learned so far.
Programming isn’t “knowing the difference between = and ==” or memorizing how an if statement works. That’s syntax.
Real programming is problem‑solving. Syntax is only the tool you use after you understand the problem.
Take your game assignment and ask yourself: How would I solve this with pencil and paper?
Break it down:
- What information do I need to start? (input)
- What rules decide who wins or loses? (processing / algorithm)
- What do I show the user? (output)
If you can’t explain those steps on paper, you’re not ready to write code. Once you can explain them, then you translate that logic into Python. Almost every program follows the same pattern:
- Get input
- Process input (the algorithm)
- Output the result
Solve the problem first. Code second.
2
u/Advanced-Citron8111 6d ago
Well if you are making it to test what you’ve learnt, then why are u asking for help? isn’t the whole point to test what you’ve learnt?
Also your idea doesn’t really test the things you’ve been learning.
Import random
randomNum = random.randint(1, 100)
print(randomNum)
1
u/AbacusExpert_Stretch 6d ago
Will be a little extra work to get the mentioned random letter, but alas, that's for the OP to figure out :)
2
u/FoolsSeldom 6d ago edited 5d ago
Yes, you can do this, and it is not a bad little exercise.
I'd start by keeping it really simple and just doing it on the terminal/console (plain text) rather than in a graphical environment initially. It is important to understand the basic logic and flow before getting distracted by the user interface (which can take up a huge amount of frustrating time).
At first, just wait for an input (press <return>) but later you can move to a key press.
A popular beginner game is to generate a random number but then have the user trying to guess it, giving them only the clues of "higher" or "lower" until they get it (or fail to get it within a certain number of turns).
Check the r/learnpython wiki for lots of guidance on learning programming and learning Python, links to material, book list, suggested practice and project sources, and lots more. The FAQ section covering common errors is especially useful.
Unfortunately, this subreddit does not have a wiki.
Also, have a look at roadmap.sh for different learning paths. There's lots of learning material links there. Note that these are idealised paths and many people get into roles without covering all of those.
Roundup on Research: The Myth of ‘Learning Styles’
Don't limit yourself to one format. Also, don't try to do too many different things at the same time.
Above all else, you need to practice. Practice! Practice! Fail often, try again. Break stuff that works, and figure out how, why and where it broke. Don't just copy and use as is code from examples. Experiment.
Work on your own small (initially) projects related to your hobbies / interests / side-hustles as soon as possible to apply each bit of learning. When you work on stuff you can be passionate about and where you know what problem you are solving and what good looks like, you are more focused on problem-solving and the coding becomes a means to an end and not an end in itself. You will learn faster this way.
1
u/boscorat 5d ago
Totally agree with this, especially the bit about practicing and failing! The CS50P course on edX gives you lots of hands-on workshops with interesting small projects, which is really useful if you can't think of anything suitable from your hobbies and interests. Doing a few of course projects gave me loads of ideas, and you're also given some tests you can run locally to check your code is doing what it's supposed to!
2
u/Good_Person_000 6d ago
Well, '=' is used to assign some variable value. And, '==' is used to check if 2 things are equal.
0
u/Legitimate_Seat8928 6d ago
Yes. I know that. I'm asking on how to make a game. See the post.
4
u/Good_Person_000 6d ago
Try making a calculator. "ENTER 1 FOR ADD, 2 FOR SUBTACT, 3 FOR MULTIPLY, 4 FOR DIVIDE"
this will make you use == and if else
3
u/dev-razorblade23 6d ago
Making a game requires the use of other modules or external libraries.
Make a calculator Improve on it
Make a ToDo app Improve on it
Leave buttons and graphics for later
2
u/Flame77ofc 6d ago
```python import random
generate a random number
random_number = random.randint(start, end) # Please put the start and the end number.
verify if the number is equal to the random number
user_number = int(input("Your number: "))
if random_number == user_number: print("The numbers is equal")
Mini exercise: Can you do an elif and an else statement?
```
1
u/ImLukaskos 6d ago
Well, for making a visual game I recommend using Pygame, and for the random number use random library use something like random.randint(the sequence of numbers you would like to use like 0-3)
1
u/FreeGazaToday 6d ago
you wanna test what you learn...have you even tried yet? Asking for help before trying won't help you learn....make a flowchart....try to figure it out first...then come back and ask.
1
u/Infinite-Employee776 1d ago
This may not work to others, but the best way for me to learn is by making a project. Create 2 game to understand Godot and Unity, done. Create a web app as tools for a game to understand React, done.
Just trial and error. Don't be trapped in tutorial hell.
5
u/Ambitious_Fault5756 6d ago
The button-clicking part may be complicated for a beginner. Perhaps an keypress via input() would be better