Python Forum
Started coding yesterday. Please review "Basic Calculator" I made.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Started coding yesterday. Please review "Basic Calculator" I made.
#4
You actually don't need 3 questions, you can string them into one:

def calculator1():
    global num1, num2, op
 
    equation = input("Enter an equation: ")
    try:
        answer = eval(equation) #This is the cool part, eval can actually take string input and do arithmetic operations with it.
        print("Your answer is: ", answer)
    except:
        print("ERROR: INVALID")

calculator1()

Also, on line 21, why do you put except Exception? That is not necessary, except by itself catches all exceptions.
Reply


Messages In This Thread
RE: Started coding yesterday. Please review "Basic Calculator" I made. - by BitPythoner - Jul-17-2020, 06:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  First time python user - Calculator code review Steamy 1 2,249 Jul-22-2020, 05:59 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020