You are on page 1of 2

Question # 1.

   

Write a programzzzs which takes two numbers and an operator symbol as user
input. You should have four different function to perform four different operations
based on the operator symbol entered by user. Then after performing the operation on
two numbers, return the result to main function and display the result on console
screen.

x=float(input("Enter first number: "))
y=float(input("Enter second number: "))
c=str(input("Enter the operator: "))
def Add(a,b):
   
        ad=a+b
        
    
        return ad
def Subtract(a,b):

        sub=a-b
       
    
        return sub
def Multiply(a,b):
   
        mul=a*b
    

        return mul
def Divide(a,b):
   
        
        div=a*b
       
    
        return div
if (c=="+"):
        v=Add(x,y)
        
        print("output of  "+str(x)+" + "+str(y)+" is equal to " + str (
v))
    
elif (c=="-"):
        v=Subtract(x,y)
        print("output of  "+str(x)+" - "+str(y)+" is equal to " + str (
v))    
elif (c=="x" or c=="X" or c=="*"):
        v=Multiply(x,y)
        print("output of  "+str(x)+" x "+str(y)+" is equal to " + str (
v))
    
    
elif (c=="/"):
        v=Divide(x,y)
        print("output of  "+str(x)+" / "+str(y)+" is equal to " + str (
v))
else:
        print("Invalid input ")
def main():
    x=float(input("Enter first number: "))
    y=float(input("Enter second number: "))
    c=str(input("Enter the operator: "))
  
    
    if __name__ == "__main__":
        main()

    

Output:

You might also like