Apr-09-2019, 11:55 AM
(This post was last modified: Apr-09-2019, 11:55 AM by souprqtpie.)
Hello
I am currently trying to create a small program which takes two numbers as given by the user and tells you if one can be divided by the other.
It works perfectly fine, but as a side subject I wanted to work out how to loop my program back to ask them to re-enter the digits if they type
something invalid such as letters.
Here is my program thus far:
Many Thanks
Soup
I am currently trying to create a small program which takes two numbers as given by the user and tells you if one can be divided by the other.
It works perfectly fine, but as a side subject I wanted to work out how to loop my program back to ask them to re-enter the digits if they type
something invalid such as letters.
Here is my program thus far:
# input asking the user for 2 numbers and assigning these numbers to variables as integers. num, check = [int(x) for x in input("Please enter two numbers: ").split()] # my function which determines whether one is divisible by the other def num_divide_by_check(x, y): if x%y == 0: print(str(x) + " is divisible by " + str(y)) else: print(str(x) + " is not divisible by " + str(y)) # putting the collected values into my function num_divide_by_check(num, check) input("Press enter to close")The second problem I face is, if the user uses anything but spaces to split up the two numbers I ask for e.g. "+" or ",". Is there a away to make my program ignore these values, or must I just add into my input asking them to split it by a space, and have any other method again recognised as an error and looped back to be re-typed.
Many Thanks
Soup