I was just going to comment but it got big.
Essentially no, after all he does very little.
Unless you want to apply a number of things that are usually recommended in terms of architecture, but it would be absurd to do this in such a simple example. Everything is context, and in this context doing the best is not the most important. I would just recommend not making absurd mistakes, not doing it anyway. In this context of a learning code it is more important to take care of readability, coding style, being correct, than good architecture, performance, etc.
Of course there are small details that can be changed, but probably more out of taste than out of necessity. So I:
- would standardize the spacing between operators
- would eventually give better names to the variables
- would care for ensure the closing of the file even if there is error, which is not even being done under normal conditions
- would do a data entry check
- would change at least the writing on the file creation screen to the location where it effectively creates the file
- would not assign values for the same variable without need (
op = 0
)
- would declare the variables closest to where they are used
- maybe use a
op > 5
in place of op >= 6
- would change the
op==0
for op <= 0
and change the message to "Os valores devem ser entre 1 e 5."
There are other perfumeries that can be made, but this is the most important for a case like this.
Notice how you’re still sinning in the basics? Don’t try to make it perfect before you hit the foundation.
Thanks guys for the tips, I haven’t used the for yet because you haven’t reached the part of the python book yet.
– Matheus da luz
This issue is being discussed here: http://meta.pt.stackoverflow.com/q/4217/3635
– Guilherme Nascimento
Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?
– Maniero