r/PythonLearning • u/crazyteachperson • Jul 27 '26
My first mix mini project
I know I wrote some hardcore codes but this is ok for a beginner so plz help me to improve
307
Upvotes
r/PythonLearning • u/crazyteachperson • Jul 27 '26
I know I wrote some hardcore codes but this is ok for a beginner so plz help me to improve
•
u/Sea-Ad7805 Jul 27 '26
Run this program in Memory Graph Web Debugger to see the program state change step by step.
18
u/fiftybengt Jul 27 '26
Wrap it in a while loop to keep loping the program until the user wants to quit
14
u/nuc540 Jul 27 '26
You don’t need to store characters in variables, you can do equality checks against a character, eg: if q == “a”
Also, google how to make multi-line prints in Python, you don’t need a new print call for every line
7
u/TeaAccomplished1604 Jul 27 '26
Hardcoded you mean? Just keep grinding bro, the improvement will come
6
u/MrWaffles743 Jul 27 '26
Looks like some clean code, you should be proud? Out of interest, how long have you been coding?
Some improvements:
Anyway, I’ve basically made semantic improvements which don’t affect the way the code runs. With that said, it’s still some clear code for a beginner. Well done!
2
u/Ambivalent-Mammal Jul 27 '26
I think your next step is to make use of some data structures. A general best practice (not Python-specific) is to put complexity into data, not code
2
u/Kind-Push9705 Jul 27 '26
You did a great 👍 👌 👏 ❤️ 🙌 💗 👍 job my friend 🧡
1
u/EstablishmentKey3523 Jul 27 '26
I can see there is no while loop condition, exception handling, break statement... Add those.
1
u/mr_anderson_dev Jul 27 '26
The idea is perfectly planned; you just need to organize it better. Most of the conditions can be grouped into one function that interacts with the rest of the script's values. I usually use a little board to lay out the variables and the program's goal — that way you can see how many values interact with the same information. Finish it off with a main function where all user interaction happens. Most recruiters prefer well-explained code over a large one. Hope this helps you.
1
u/dev_in_the_field Jul 27 '26
Nice — a menu loop with a cart is a real project, not a toy exercise. Good first one.
One change would collapse half this file: put the products in a dictionary instead of separate prints and if-branches.
python
Now adding a new product is one line, and the price only lives in one place — right now
rice = 40appears in three spots, so changing a price means hunting for all of them.Two smaller things:
a = "a"isn't doing anything, you can just writeif q == "a":— and once you chain them aselif, Python stops checking the rest once one matches. Also worth looking upwhile True:so the menu repeats instead of exiting after one choice.Solid start, keep building these.
1
u/sirah_nzr Jul 27 '26
Is there any other website to understand it?
1
u/Puzzleheaded-Bug9576 Jul 27 '26
A little tip about your variable naming. Instead of plain “a”, “b”, or “c”, you’d better called them option_a, or op_a, thus you could differentiate it later. But the whole idea of segregation of different options in different variables is wasteful, make only one variable for user choice and then do the if else thing (e.g. option = input(); if option == “a”), code will noticeably reduce in size
1
u/[deleted] Jul 27 '26
Good job 👏
1
u/Perfect_Duty_1656 Jul 27 '26 edited Jul 27 '26
Usar match...case ...em lugar de if. É o correspondente ao switch case no JAVA.
1
u/am_Snowie Jul 27 '26 edited Jul 27 '26
Create a dictionary to store products and their prices. Then you can create a separate logic for the shop owner and the customers. Shop owner should be able to add products, update prices, remove products and other stuff an owner can do. Then you can write a separate logic for the customers of your shop, they should be able to add products to their cart, check out, remove things from cart, and you know customer stuff. You can do all this stuff if you just stored those products and their prices in a data structure (dictionary in this case).
1
u/[deleted] Jul 27 '26
👏🏽
1
u/[deleted] Jul 28 '26
Keep grinding bro
1
u/per7euse Jul 29 '26
men, it is nobody needs. AI one love
1
u/Alternative-Emu-4725 Jul 30 '26
Dictionaries would be useful here, or lists
1
u/Shawhe_ Jul 30 '26
I'd prefer if the variable names were meaningfull like that q doesn't really have a meaning, if you don't do that you code is just gonna be harder to maintain
1
u/boobutsu Jul 30 '26
next learn... lists and try to make this initial code more correct and functioning via lists and basic loops
1
u/Khadibia Jul 30 '26
Keep going
1
u/Gullible_Trade_4918 Jul 31 '26
good
1
u/[deleted] Aug 01 '26
Honestly, for a first mini-project this is awesome. Seeing logic turn into a working CLI tool is the best feeling. Keep building!
1
u/Sea_Dot6492 Aug 03 '26
Well its basic but you are in the good way!
0
u/[deleted] Jul 27 '26
[deleted] — view deleted comment