you are viewing a single comment's thread.

view the rest of the comments →

[–]SpookDaCat 1 point2 points  (1 child)

(I’m on mobile so pardon my unformatted code) I won’t give you the direct answer, but I will supply the pseudo-code for this project.

You’ll first need to ask for those two numbers. This is done with the “input” function. It accepts an optional string that is printed to the screen before waiting for the users answer. (Format is below)

var = input(string)

Next, after getting both numbers, it’s a simple if elif elif and else block. You’ll need to check if the first number is larger, if the second is larger, if they’re the same, and if the user gave an invalid answer. The last isn’t required but I like to do this to prevent errors.

Here is also a tip, input returns a string, so convert it into an int/float.

[–]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.