This is my code : I attached my outputs and expected outputs as screen shots. I need to get the last expected output. Please see the screenshots I attached.Does anybody can help me?
This is the task.
Task 1: Get user input
Section 1:
Input Arithmetic operation Reset or Termination Section 2:
Input first operand Input second operand Reset or Termination Task 2: Implement functions that performs given arithmetic operation on the given operands and produces the result
Arithmetic operation and the two operands as parameters Return the result of the arithmetic operation
Task 3: Call the calculation function by passing user input to select_op(choice) and display the result from within the select_op(choice) function
Here are some of the messages you might want to display to the users at certain occasions. Copy and paste them as necessary in your code in appropriate situations to help with auto-grading. If there is any differences between the output of your code and the expected output, it will be displayed once you click the "Check" button. You can click on "Show differences" button to highlight the difference between outputs. This will be helpful for you to change your code to match the expected output.
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
def power(x, y):
return x ** y
def remainder(x, y):
return x % y
def select_op(choice):
if choice == '+':
num1 = int(input("Enter first number: "))
print(num1)
num2 = int(input("Enter second number: "))
print(num2)
print(float(num1), "+", float(num2), "=", float(add(num1, num2)))
elif choice == '-':
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print(num1, "-", num2, "=", subtract(num1, num2))
elif choice == '*':
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print(num1, "*", num2, "=", multiply(num1, num2))
elif choice == '/':
num1 = int(input("Enter first number: "))
print(num1)
num2 = int(input("Enter second number: "))
print(num2)
try:
result = num1 / num2
print(f"{num1} / {num2} = {result}")
except ZeroDivisionError:
print("float division by zero")
print(float(num1), "/", float(num2), "=", "None")
elif choice == '^':
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print(num1, "^", num2, "=", power(num1, num2))
elif choice == '%':
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print(num1, "%", num2, "=", remainder(num1, num2))
elif choice == '#':
return -1
elif choice == '$':
return 0
else:
print("Invalid input")
return 1
while True:
print("Select operation.")
print("1.Add : + ")
print("2.Subtract : - ")
print("3.Multiply : * ")
print("4.Divide : / ")
print("5.Power : ^ ")
print("6.Remainder: % ")
print("7.Terminate: # ")
print("8.Reset : $ ")
# take input from the user
choice = input("Enter choice(+,-,*,/,^,%,#,$): ")
print(choice)
if select_op(choice) == -1:
print("Done. Terminating")
exit()
Output 1 : correct
(https://i.stack.imgur.com/8JYL1.png)
Output 2 : correct
(https://i.stack.imgur.com/tqokg.png)
Output 3 : correct
(https://i.stack.imgur.com/8Wcd3.png)