I need fix this code Please help me   def add(a,b):     return a+b def subtract(a,b):     return a-b def multiply (a,b):     return a*b def divide(a,b):     try:         return a/b     except Exception as e:         print(e) def power(a,b):     return a**b def remainder(a,b):     return a%b def select_op(choice):     if choice == '#':         return -1     elif choice == '$':         return 0     elif choice in ('+', '-', '*', '/', '^', '%'):         while True:             num1s = input("Enter first number: ")             print(num1s)             if num1s.endswith('$'):                 return 0             if num1s.endswith('#'):                 return -1         try:             num1 = float(num1s)         except:             print("Not a valid number, please enter again")         while True:             num2s = input("Enter second number: ")             print(num2s)             if num2s.endswith('$'):                 return 0             if num2s.endswith('#'):                 return -1             try:                   num2 = float(num2s)                 break             except:                 print("Not a valid number, please enter again")                 continue         result = 0.0         last_calculation = ""         if choice == '+':             result = add(num1, num2)         elif choice == '-':             result = subtract(num1, num2)         elif choice == '*':             result = multiply(num1, num2)         elif choice == '/':             result =  divide(num1, num2)         elif choice == '^':             result = power(num1, num2)         elif choice == '%':             result = remainder(num1, num2)         else:             print("Something Went Wrong")         last_calculation =  "{0} {1} {2} = {3}".format(num1, choice, num2, result)          print(last_calculation)         record_history(last_calculation)     elif choice == '?':         history()      else:         print("Unrecognized operation") 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:         #program ends here         print("Done. Terminating")         break

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need fix this code Please help me

 

def add(a,b):

    return a+b

def subtract(a,b):
    return a-b

def multiply (a,b):
    return a*b

def divide(a,b):
    try:
        return a/b
    except Exception as e:
        print(e)

def power(a,b):
    return a**b

def remainder(a,b):
    return a%b

def select_op(choice):
    if choice == '#':
        return -1
    elif choice == '$':
        return 0
    elif choice in ('+', '-', '*', '/', '^', '%'):
        while True:
            num1s = input("Enter first number: ")
            print(num1s)
            if num1s.endswith('$'):
                return 0
            if num1s.endswith('#'):
                return -1

        try:
            num1 = float(num1s)

        except:
            print("Not a valid number, please enter again")


        while True:
            num2s = input("Enter second number: ")
            print(num2s)
            if num2s.endswith('$'):
                return 0
            if num2s.endswith('#'):
                return -1
            try:  
                num2 = float(num2s)
                break
            except:
                print("Not a valid number, please enter again")
                continue

        result = 0.0
        last_calculation = ""

        if choice == '+':
            result = add(num1, num2)
        elif choice == '-':
            result = subtract(num1, num2)
        elif choice == '*':
            result = multiply(num1, num2)
        elif choice == '/':
            result =  divide(num1, num2)
        elif choice == '^':
            result = power(num1, num2)
        elif choice == '%':
            result = remainder(num1, num2)
        else:
            print("Something Went Wrong")

        last_calculation =  "{0} {1} {2} = {3}".format(num1, choice, num2, result) 
        print(last_calculation)
        record_history(last_calculation)

    elif choice == '?':
        history() 

    else:
        print("Unrecognized operation")

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:
        #program ends here
        print("Done. Terminating")
        break

11:45 •
7.1 Programming a Calculator Stage 1
https://open.uom.lk/mod/quiz/attempt.php
Subtract :
Multiply : *,
Divide : /
Power
:
<
Remainder: %
Terminate: #
: $
Reset
ter choice(+,-,*,/,^,%,#,$): --
ter first number: 2
כ
ter second number: #2
ne. Terminating
Tsu
2. Subtract :
3. Multiply
4. Divide
5. Power
6. Remainder: %
7. Terminate: #
8. Reset
: $
Enter choice(+,-,*,/,^,
Enter first number: 20
Enter first number: #2
Done. Terminating
*
: /
A
4G
| 46 | 62%
个
כ)
^,%
r
O
|||
Transcribed Image Text:11:45 • 7.1 Programming a Calculator Stage 1 https://open.uom.lk/mod/quiz/attempt.php Subtract : Multiply : *, Divide : / Power : < Remainder: % Terminate: # : $ Reset ter choice(+,-,*,/,^,%,#,$): -- ter first number: 2 כ ter second number: #2 ne. Terminating Tsu 2. Subtract : 3. Multiply 4. Divide 5. Power 6. Remainder: % 7. Terminate: # 8. Reset : $ Enter choice(+,-,*,/,^, Enter first number: 20 Enter first number: #2 Done. Terminating * : / A 4G | 46 | 62% 个 כ) ^,% r O |||
11:46 8.
7.1 Programming a Calculator Stage 1
https://open.uom.lk/mod/quiz/attempt.php
Enter choice(+,-,*,/,^,%, #,$): +2
Enter first number: 2+
Enter second number: 4-
2.0 + 4.0
=
ܒ6.0
Select operation.
1. Add
2.Subtract :
3. Multiply :
4. Divide : / <
5. Power
: ^
6. Remainder: %-
7. Terminate: #-
ܒܢ
K
4G
|| 46 | 62%
Enter choice(+,-,*,/,
Enter first number: 2
Enter first number: 4
Enter first number: #
Done. Terminating
r
||||
Transcribed Image Text:11:46 8. 7.1 Programming a Calculator Stage 1 https://open.uom.lk/mod/quiz/attempt.php Enter choice(+,-,*,/,^,%, #,$): +2 Enter first number: 2+ Enter second number: 4- 2.0 + 4.0 = ܒ6.0 Select operation. 1. Add 2.Subtract : 3. Multiply : 4. Divide : / < 5. Power : ^ 6. Remainder: %- 7. Terminate: #- ܒܢ K 4G || 46 | 62% Enter choice(+,-,*,/, Enter first number: 2 Enter first number: 4 Enter first number: # Done. Terminating r ||||
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education