Of course, the easiest one is Google Calculator, but try of CalculatorSoup for
other tpyes of calculations such as finiding the interest or else calculating
fractions!
By Codexel
If you divide any number by 0 (N/0). The answer should be NA (Not Assigned) and not infinity.
This is some high level math concept which grepper is too small to be explained on.
I recommend watching a YouTube video.
class calc:
def __init__(self,num):
self.num = num
def __add__(self,other):
#inner code
def __mul__(self, other):
#inner code
def __sub__(self, other):
#inner code
def __div__(self,other):
#inner code
# and so on for features
# Calculator
def addition ():
print("Addition")
n = float(input("Enter the number: "))
t = 0 #Total number enter
ans = 0
while n != 0:
ans = ans + n
t+=1
n = float(input("Enter another number (0 to calculate): "))
return [ans,t]
def subtraction ():
print("Subtraction");
n = float(input("Enter the number: "))
t = 0 #Total number enter
sum = 0
while n != 0:
ans = ans - n
t+=1
n = float(input("Enter another number (0 to calculate): "))
return [ans,t]
def multiplication ():
print("Multiplication")
n = float(input("Enter the number: "))
t = 0 #Total number enter
ans = 1
while n != 0:
ans = ans * n
t+=1
n = float(input("Enter another number (0 to calculate): "))
return [ans,t]
def average():
an = []
an = addition()
t = an[1]
a = an[0]
ans = a / t
return [ans,t]
# main...
while True:
list = []
print(" My first python program!")
print(" Simple Calculator in python by Malik Umer Farooq")
print(" Enter 'a' for addition")
print(" Enter 's' for substraction")
print(" Enter 'm' for multiplication")
print(" Enter 'v' for average")
print(" Enter 'q' for quit")
c = input(" ")
if c != 'q':
if c == 'a':
list = addition()
print("Ans = ", list[0], " total inputs ",list[1])
elif c == 's':
list = subtraction()
print("Ans = ", list[0], " total inputs ",list[1])
elif c == 'm':
list = multiplication()
print("Ans = ", list[0], " total inputs ",list[1])
elif c == 'v':
list = average()
print("Ans = ", list[0], " total inputs ",list[1])
else:
print ("Sorry, invilid character")
else:
break