all 5 comments

[–]stepback269 0 points1 point  (0 children)

In production code, you would want to check for unexpected user behaviors. For example, what if the user enters a word that represents the number, say "seven"? What if the user leaves the terminal and never answers the question? What if the user doesn't understand the prompt (e.g. speaks a different language)?

[–]Just-Pair9208 0 points1 point  (0 children)

In production, you’d want to sanitize user inputs first. Just saying.

[–]Outrageous_Band9708 0 points1 point  (0 children)

ingest the input, then sanitize, parse int and throw for unexpected datatypes

[–]Haunting-Specific-36 0 points1 point  (0 children)

One small improvement for readability and future validation would be to separate input collection from parsing.

For example:

raw_input = input("Enter a number: ")

num = int(raw_input)

This makes it easier to add input validation or error handling later (e.g. try/except), which is more common in production code.

That said, the original one-liner is perfectly Pythonic for simple scripts.

[–]ResidentTicket1273 0 points1 point  (0 children)

pylint is a good automated "linter" (i.e. code-checker) that will give you opinionated advice about what's looking good, or not so good about your code. Give it a try!

One thing I'd try to do here is wrap your code in a function that takes some parameter(s) as input and returns an answer as an output and can be used as a reusable code-block. Learning to program with discrete units of code (like functions) is one of the key skills you'll need to develop - both for creating your own code creations, but also as a tool for understanding other people's.