Answers for "how to create a calcualtor in python3"

0

how to make a calculator in python

# This will be one of the most advanced results you will find.

# We will be using classes and simple operators like +,-,*,/

class Calculator:
  def addition(a,b):
    return a + b

  def subtraction(a,b):
    if a<b:
      return b - a
    else:
      return a - b

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

  def division(a,b):	
    if a<b:
      return b / a
    else:
      return a / b

# You can do this in terminal.
<C:/Users/username>python
>>> from main import Calculator
>>> result = Calculator.[addition|subtraction|multiplication|division](anyNumber, anyNumber)
>>> print(result)
Posted by: Guest on October-11-2020
-1

how to make a calculator using python

#no gui

def  add(a,b):
    result=a+b
    print(result)

def sub(a,b):
    resulf=a-b
    print(resulf)

def mul(a,b):
    resulf=a*b
    print(resulf)

def div(a,b):
    resulf=a/b
    print(resulf)

a=int(input("enter th first number: "))
b=int(input("enter th second number: "))
op=input("enter the sign: ")

if op=="+":
    add(a,b)

elif op=="-":
    sub(a,b)    

elif op=="*":
    mul(a,b)  

elif op=="/":
    div(a,b)    

else:
    print("invalid")
Posted by: Guest on August-14-2021

Code answers related to "how to create a calcualtor in python3"

Python Answers by Framework

Browse Popular Code Answers by Language