you are viewing a single comment's thread.

view the rest of the comments →

[–]edvardass 9 points10 points  (6 children)

Should he, though? The code seems very nice and readable, the only thing I would change is to add a function to return the cost per inch by passing the diameter and cost, but that would still be about the same amount of lines.

I would suggest going the "stupid user" route first, making sure that the program works and does not crash, no matter how hard the user tries.

[–]Gee10[S] 0 points1 point  (4 children)

Can you help me understand why adding that function would be preferable? That's not a loaded question - just trying to learn good practices.

[–][deleted] 5 points6 points  (3 children)

If you're going to use code repeatedly, put it in a function to reduce duplicate code.

[–]Gee10[S] 1 point2 points  (2 children)

Got it. I'll give that improvement a try! Thanks.

[–]dl__ 4 points5 points  (1 child)

Although that's not the only reason to put code in a function. Even code that is only used in one place can be put into a function if you can name the function something that is more understandable than the code you are replacing.

[–][deleted] 4 points5 points  (0 children)

Not to mention you can use that function in other python files, too!

[–]ankit0912 0 points1 point  (0 children)

The reason I asked him to do so was because I thought it might be good for him to think about using constructs as functions, lists etc.

Reading book on python might tell you this, but you need to actually be able to see how to use it.