Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please see picture below for the directions. def add (a, b) : # Defined function for addition return a + b # Result def mul
Please see picture below for the directions.
def add(a, b): # Defined function for addition return a + b # Resultdef mul(a, b): # Defined function for multiplication return a * b # Resultdef sub(a, b): # Defined function for substraction return a - b # Resultdef div(a, b): # Defined function for division try: # First exception should be present for the divide by zero value = a/b return value except ZeroDivisionError: print("You can't divide by zero!") return Nonedef IsInRange(lr, hr, n): # Defined function to test a value between two ranges if n >= lr and n return True # Result else: return False # Resultdef main(): while (True): try: # Second should be for the protection of adding strings instead of integer. minRange = int(input('Enter your Lower range ---> ')) # User Defined Lower Range maxRange = int(input('Enter your Higher range ---> ')) # User Defined Higher Range while (maxRange # minRange can't be higher that maxRange minRange = int(input('Re-Enter your Lower range ---> ')) maxRange = int(input('Re-Enter your Higher range ---> ')) first = int(input('Enter your First number ---> ')) # User Defined First Number while not IsInRange(minRange, maxRange, first): # User Defined First Number can't be higher than maxRange first = int(input('Re-Enter your First number in the range ---> ')) second = int(input('Enter your Second number ---> ')) # User Defined Second Number while not IsInRange(minRange, maxRange, second): # User Defined First Number can't be higher than maxRange second = int(input('Re-Enter your second number in the range ---> ')) print(" The Result of ", first, "+", second, "=", add(first, second)) # Print Result print("The Result of ", first, "-", second, "=", sub(first, second)) # Print Result print("The Result of ", first, "*", second, "=", mul(first, second)) # Print Result division = div(first, second) if division: print("The Result of ", first, "/", second, "=", division) choice = input("Make Another Try again? ") # prompt user with a choice if he/she wants to try again if (choice == 'Yes'): # start calculator over if user makes the following choice continue else: # if choice isn't met calculator will terminate with thanking user for using this calculator print("Thanks for using our calculator! ") break except ValueError: print('Enter the integer value')main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started