Simple Arithmetic Calculator - User Defined Function
Type 1:
#Function Definition
def add():
print("Addition:")
a=int(input("Enter A Value: "))
b=int(input("Enter B Value: "))
c=a+b
return(c)
sum=add() #Function Call
print("Addition: ",sum)
def diff():
print('\n'"Subtraction:")
a=int(input("Enter A Value: "))
b=int(input("Enter B Value: "))
c=a-b
return(c)
sub=diff()
print("Subtract: ",sub)
def mul():
print('\n'"Multiplication:")
a=int(input("Enter A Value: "))
b=int(input("Enter B Value: "))
c=a*b
return(c)
multi=mul()
print("Multiplication: ",multi)
def div():
print('\n'"Division:")
a=int(input("Enter A Value: "))
b=int(input("Enter B Value: "))
c=a/b
return(c)
divide=div()
print("Division: ",divide)
Output:
Type 2:
#First Calculator
def add(a,b):
c=a+b
return(c)
def diff(a,b):
return(a-b)
def pro(a,b):
return(a*b)
def quo(a,b):
return(a//b)
def rem(a,b):
return(a%b)
def line():
print("**********************")
line()
print("My First Calculator")
line()
a=int(input("Enter A Value: "))
b=int(input("Enter B Value: "))
print('\n'"Addition: ",add(a,b))
print("Subtract: ",diff(a,b))
print("Product : ",pro(a,b))
print("Quotient: ",quo(a,b))
print("Reminder: ",rem(a,b))
line()
print("Thank You")
line()
If you have any doubts, feel free to post it in comment Section.
Comments