Answers for "basic py calculator"

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

python calculator

print("Choose operator (+,-,*,/):")
mode = input()
print("Choose first int:")
x = int(input())
print("Choose second int:")
y = int(input())

print("Your result:")
if mode == "+":
    print(x+y)
elif mode == "-":
    print(x-y)
elif mode == "*":
    print(x*y)
elif mode == "/":
    print(x/y)
Posted by: Guest on November-02-2020

Python Answers by Framework

Browse Popular Code Answers by Language