Hello everyone,
My name is Thai and I am new to Python. I have a question and really need your help so that I can have a better understanding about Python. The original problem is about the division operation between two numbers whichever is greater. I already had my code but I would like to modify it a little bit in such a way that if I enter "exit" or "e" for either the first or second number, the program will stop immediately. For example, if I enter "exit" for the first number, the program will stop without entering the second number. Here is my codes. Thank you for your help.
My name is Thai and I am new to Python. I have a question and really need your help so that I can have a better understanding about Python. The original problem is about the division operation between two numbers whichever is greater. I already had my code but I would like to modify it a little bit in such a way that if I enter "exit" or "e" for either the first or second number, the program will stop immediately. For example, if I enter "exit" for the first number, the program will stop without entering the second number. Here is my codes. Thank you for your help.
while True: num_1 = input("enter your first number: ") if num_1.isdigit() == False: print("Invalid Input") else: break while True: num_2 = input("enter your second number: ") if num_2.isdigit() == False: print("Invalid Input") else: break while True: if int(num_1) == 0 or int(num_2) == 0: print("Cannot divide by zero. The answer is zero by default.") break if int(num_1) > int(num_2): print("The answer is ",int(int(num_1) / int(num_2))) break if int(num_1) < int(num_2): print("The answer is ",int(int(num_2) / int(num_1))) break if int(num_1) == int(num_2): print("Two number are equal. The answer is one.") break