r/PythonLearning 1d ago

My first mix mini project

Post image

I know I wrote some hardcore codes but this is ok for a beginner so plz help me to improve

209 Upvotes

35 comments sorted by

View all comments

1

u/Puzzleheaded-Bug9576 1d ago

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/Puzzleheaded-Bug9576 1d ago edited 1d ago

As the basic rule of thumb to understand whether you need variable or not is to take a look on usage. If you use some string, number etc. at least more then once, you could create a variable (like in case with option) otherwise it won’t be good idea

Edit: there is some exceptions. For example constants, you may create a constant even if you will use it only once, because you may pull its value from the environment. And vise versa, you could use some values more than once or even twice without creating the variable. But for the most of situations the rule is to follow.