Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

python flask 2 Web Calculator[40 points Write a Flask application whose index pa

ID: 3718768 • Letter: P

Question

python flask

2 Web Calculator[40 points Write a Flask application whose index page contains a form similar to the one shown in Figure 2. The user should be able to enter two numbers, and choose the desired operation. Once the user clicks submit, your application should redirect to /result/ (e.g., /result/add) and there it should display the result to the user, along with a link back to the index page. Your application should check for invalid inputs s.?., it needs to ensure the inputs are integers or floats) and redirect to another page(e.g., /result/error/) where an error message will be displayed to the user, with a link back to the index page. Your application should also feature custom error pages for 404, 403 and 500 status codes (Contents of these pages are up to you). Your design elements should be decoupled from the Python code, and the overall design needs to be modular. You should concentrate on avoiding repeating code as much as possible First number: Second number Add Subtract O Multiply O Divide Submit

Explanation / Answer

Okay so construct a simple Calculator using Python, we will define functions for Addition,Substraction,Multiplication and Division.

Now to run the Program after each Calculation, we apply a while loop, which runs the complete program, and on a particular condition terminates.

quit() function is used to terminate a Program.

Program is given Below: -

def add(x, y):
return x + y

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

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

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


while (input("To start Calculator Press any Key"):
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
print("5.Quit")
  
choice = input("Enter choice(1/2/3/4/5):")

num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

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

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

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

elif choice == '4':
print(num1,"/",num2,"=", divide(num1,num2))
print("----------")
elif choice == '5':
quit()

else:
print("Invalid input")
print("----------")
else:
print("Thank You for using the Calculator")

This will work as a calculator, and will quit if 5 is entered.

Thank You for using Chegg..

Okay so construct a simple Calculator using Python, we will define functions for Addition,Substraction,Multiplication and Division.

Now to run the Program after each Calculation, we apply a while loop, which runs the complete program, and on a particular condition terminates.

quit() function is used to terminate a Program.

Program is given Below: -

def add(x, y):
return x + y

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

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

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


while (input("To start Calculator Press any Key"):
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
print("5.Quit")
  
choice = input("Enter choice(1/2/3/4/5):")

num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

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

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

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

elif choice == '4':
print(num1,"/",num2,"=", divide(num1,num2))
print("----------")
elif choice == '5':
quit()

else:
print("Invalid input")
print("----------")
else:
print("Thank You for using the Calculator")

This will work as a calculator, and will quit if 5 is entered.

Thank You for using Chegg..