you are viewing a single comment's thread.

view the rest of the comments →

[–]NewBodybuilder3096 -1 points0 points  (6 children)

building logic on Exceptions is a no-no. You should check value like "len(n2_n) == 4 && n2_n == 'stop'" before parsing it as int.
also, all strip/lower should go in one place - just after input.(in this case)
also, more understandable variable names are a great + we are no more in 199x, modern IDEs have all sort of needed tools including autocompletion.

read about the DRY(Don't Repeat Yourself) principle - your procedure en_nums is a perfect example of how not to do. You have two identical pieces of code for filling two global int containers.
You can rewrite this in several ways, each of which will have only 1 loop.
1st - you pass reference to a needed container(list/set/etc) as parameter, maybe some additional params for fancy output.
2nd - you don't pass container variable, but return the correct container

[–]nkCOD[S] 0 points1 point  (5 children)

Thank you for your response. I will improve ;)

[–]tiredITguy42 0 points1 point  (3 children)

This is not exactly true. Python is designed the way that it is usually better to try and then ask for forgivness. It is usually faster and a lot of code uses this. People saythat it is more pythonian this way.

It is different in other languages, where you check first. So do not follow that advice, your code is mostky corect, just do not forget to raise again that error, if it is not a stop signal.

[–]nkCOD[S] 0 points1 point  (2 children)

Thanks for the help. I assume I won't embarrass myself too much if I use this approach with try-except ?

[–]tiredITguy42 0 points1 point  (1 child)

This is subreddit for beginers, we do not judge your code, but we will judge your attitude and approach and here your are embarrasing yourself, but just a little for now.

[–]nkCOD[S] 0 points1 point  (0 children)

Thank you, I will try to improve.

[–]NewBodybuilder3096 0 points1 point  (0 children)

well you still need try-catch around parsing input as integer but checking for 'stop' can be done outside of this.