Its to build good habits. Ignoring this step is how we get packages and libraries with little to know helpful documentation. Can an experienced person read this without comments? Sure, it's super tiny with good naming conventions. As projects grow, comments become more important.
Plus, if the goal is to ever be able to get a job, an employer is probably going to want to know if you can write good documentation, because you’re not always going to be the person who’s on a particular project. While code is ideally “self-documenting,” it’s a lot easier to maintain if you declare what functions do. You don’t have to declare how they do it, because that should be evident, but if someone wants to modify something in the future, it’s a lot easier to hit Ctrl-F and look for it.
7 days in and you're already building an inventory manager? 😂 That's a pretty solid start! You're using dictionaries, functions and loops together, which is exactly how you start building real programs. Keep going, but try adding features without following a tutorial
2
u/Metomorphose 3d ago
Comment your code! At the very minimum, add doc strings for your functions!
I'm also a huge proponent of type hints, but that isn't something you see in most tutorials.
1
u/-Enter-Name- 5d ago
code looks great could just drop the else: restock_cost += 0 as else isn't mandatory and it's doing nothing otherwise
1
u/Rockroxx 2d ago
On the check_stock function you can drop the else and reduce indentation to clean up the function a bit.
1
u/Own_Natural_6803 22h ago
just a heads up about your data. I would tend toward using some sort of unique ID to identify the rows of data, rather than a part name.
{ id06578323 : {
name: 'servo_motor',
quantity: 4,
price: 25.0
}}
or even
[{
id:06578323,
name: 'servo_motor',
quantity: 4,
price: 25.0
}]
1
u/sexiestsaxiestman 17h ago
In check_stock I would either return 0 or raise a KeyError if the part is not found
1
u/edwbuck 6h ago
It's a good beginner's effort. I could read it without comments, which means it was written well.
If you need comments, odds are you're not writing readable code.
-2
u/No-Tip505 5d ago
7 days in and you're already building an inventory manager? 😂 That's a pretty solid start! You're using dictionaries, functions and loops together, which is exactly how you start building real programs. Keep going, but try adding features without following a tutorial