How to print an error saying that an integer must be entered if either input value is not a number, and multiply x by y when no error is caught

I am trying to make it so that if either input value is not a number, it will print an error message saying that an integer must be entered. And whenever no error is caught, it will multiply x by y. How would I do this?

Here is what I have so far:

def main():
    try:
        x = int(input("Please enter a number: "))
        y = int(input("Please enter another number: "))
    except:

>Solution :

It’s good practice to not have empty except as it makes debugging difficult

def main():
    try:
        
        x = int(input("Please enter a number: "))
        y = int(input("Please enter another number: "))
        print(x*y)
    
    except(ValueError):
        print("An integer must be entered. ")
main()

One thought on “How to print an error saying that an integer must be entered if either input value is not a number, and multiply x by y when no error is caught

Leave a Reply