Oct-01-2023, 07:36 PM
[inline]
Hello deanhystad, thanks a bunchhh the code you suggested worked fine for all wrong inputs!!! Grateful.
Just learning Python, so getting my hands on writing codes related to real life problems.
[/inline]
Hello deanhystad, thanks a bunchhh the code you suggested worked fine for all wrong inputs!!! Grateful.
Just learning Python, so getting my hands on writing codes related to real life problems.
[/inline]
def input_int(prompt): while True: try: inp = input(prompt) return int(inp) except ValueError as msg: print(msg) dividend = input_int("Enter integer dividend: ") while True: if divisor := input_int("Enter integer divisor: "): break print("Divisor cannot be zero.") def modulus(dividend): rem = dividend % divisor qout= dividend // divisor return (f"{dividend} modulo {divisor} has a remainder of {rem}") print(modulus(dividend))
Output:Enter integer dividend: 8
Enter integer divisor: 0
Divisor cannot be zero.
Enter integer divisor: 2
8 modulo 2 has a remainder of 0