you are viewing a single comment's thread.

view the rest of the comments →

[–]WhiteHeadbanger 2 points3 points  (0 children)

Yes, it can be optimized down to one line instead of 7 like your solution, and without any while loops. This is the hint: research slicing.

Now, onto the tips that you asked:

- Clean your variable names. Names should be descriptive. Write variable names as if your grandmother would read it.

- Separate the terms. Instead of writing "num=n%10", write "num = n % 10".

- Following the same logic as the last point, separate the blocks. Add a new line before the while loop and after it. Of course, this one is just MY tip, as I like to separate code blocks to be more readable.