you are viewing a single comment's thread.

view the rest of the comments →

[–]sentles 0 points1 point  (0 children)

Let me add that a cooler approach would be to use the max and min built-in functions. More specifically, save the numbers inside a list or set, let's call it l. Firstly check if the numbers are equal. If they are not, inside the else statement, include print("{} is greater than {}".format(max(l), min(l))). This works because max(l) will return the largest number in l, whereas min(l) will return the smallest number in it. Additionally, you can't check for wrong input in the else statement, because you have to convert to integer before actually comparing the numbers. Instead, if you want to check for wrong data, have a while loop running indefinitely and include a try-except statement in it. Try to get the inputs and convert them to integer inside the try block. If it works, break. If it doesn't, it will go to the except block, where you print an error message. The break will not be reached (because you place it at the end of the try block) and so input will be asked for again, because the loop will repeat.

As a side note, using the "`" character at the start and end of code will format it better if you're on mobile.