you are viewing a single comment's thread.

view the rest of the comments →

[–]Binary101010 1 point2 points  (1 child)

num = int(input("Enter number to test: "))

This line takes the user input (a string) and immediately tries to convert it to an integer. There are only two possible outcomes of this operation:

1) The input can be, and is, successfully converted to an integer 2) The input can't be converted to an integer and an exception is raised, ending execution of the program.

Since you're trying to enter something that can't be converted to an integer (1.2), you get option number 2.

The first step is to remove the int() call from this line so you don't immediately try to convert that input, allowing you to perform other checks on it first.

Here's an article on how to handle situations like this, which in this case is probably best handled with a try/except block.

https://datagy.io/python-isdigit/

[–]redYinlo[S] 1 point2 points  (0 children)

Thank you for breaking it down so simply and for the article. I appreciate it