Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

add a function to get input from the user and to make sure that the user enters a valid integer from 1 to 100 for

add a function to get input from the user and to make sure that the user enters a valid integer from 1 to 100 for each value, and to handle exceptions if the user enters a non-numeric value

Use that function to get the input for each calculation

(please show me where to add or remove the code and show me the after result of the code)

# addition function def add(x, y): return x + y

# subtract function def subtract(x, y): return x - y

# multiply function def multiply(x, y): return x * y

# divide function def divide(x, y): return x / y

print("Select operation.") print("1.Addtion") print("2.Subtraction") print("3.Multiply") print("4.Dividion")

while True: # take input from the user choice = input("Enter choice(1/2/3/4): ")

# check if choice is one of the four options if choice in ('1', '2', '3', '4'): try: num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) except ValueError: print("Invalid input. Please enter a number.") continue

if choice == '1': print(num1, "+", num2, "=", add(num1, num2))

elif choice == '2': print(num1, "-", num2, "=", subtract(num1, num2))

elif choice == '3': print(num1, "*", num2, "=", multiply(num1, num2))

elif choice == '4': print(num1, "/", num2, "=", divide(num1, num2)) # check if user wants another calculation # break the while loop if answer is no next_calculation = input("Let's do next calculation? (y/n): ") if next_calculation == "n": break else: print("Invalid Input")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

Explain the various methods of job evaluation

Answered: 1 week ago

Question

Differentiate Personnel Management and Human Resource Management

Answered: 1 week ago

Question

Describe the functions of Human resource management

Answered: 1 week ago

Question

What were your most important educational experiences?

Answered: 1 week ago

Question

Which personal relationships influenced you the most?

Answered: 1 week ago