Python Editor

Python | Lesson3 | Functions - Addition


def add(x, y):
   "This function adds two numbers"
   return x + y

num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))

print("sum of num1,num2 =", add(num1,num2))


# Todo :  Create Subtraction, Multiplication and division functions,
# and print the results using the functions similar to add function 


4 comments:

  1. def add(x, y):
    "This function adds two numbers"
    return x + y

    def subtract(x, y):
    "This function subtracts two numbers"
    return x - y

    num1 = float(input("Enter first number: "))
    num2 = float(input("Enter second number: "))

    print("sum of num1,num2 =", add(num1,num2))
    print ("difference of num1, num2 =", subtract(num1, num2))

    ReplyDelete
  2. All Order of Operations Calculator

    def add(x, y):
    "This function adds two numbers"
    return x + y

    def subtract(x, y):
    "This function subtracts two numbers"
    return x - y

    def multiply(x, y):
    "This function multiplies two numbers"
    return x * y

    def divide(x, y):
    "This function divides two numbers"
    return x / y

    num1 = float(input("Enter first number: "))
    num2 = float(input("Enter second number: "))

    print("sum of num1,num2 =", add(num1,num2))
    print ("difference of num1, num2 =", subtract(num1, num2))
    print ("result of multiplying num1, num2 =", multiply(num1, num2))
    print ("quotient of num1, num2 =", divide(num1, num2))

    - Srijan

    ReplyDelete
  3. def add(x, y):
    "This function adds two numbers"
    return x + y

    def subtract(x, y):
    "This function subtracts two numbers"
    return x - y

    num1 = float(input("Enter first number: "))
    num2 = float(input("Enter second number: "))

    print("sum of num1,num2 =", add(num1,num2))
    print ("difference of num1, num2 =", subtract(num1, num2))

    --Surya

    ReplyDelete
  4. def add (x,y):
    "This function adds two numbers"
    return x+y

    def subtract (x,y):
    "This function subtracts two numbers"
    return x-y

    def multiply (x,y):
    "This function multiplies two numbers"
    return x*y


    num1 = float(input("Enter first number: "))
    num2 = float(input("Enter second number: "))

    print("of num1, num2 =", add(num1, num2))
    print("multiplication of num1, num2=", multiply(num1, num2))
    print("subtraction of num1, num2=", subtract (num1, num2))

    def divide (x,y):
    "This function divides two numbers"
    return x/y


    num1 = float(input("Enter first number"))
    num2 - float(input( "Enter seond number"))

    print("of num1, num2 =", divide(num1, num2))
    print("division of num1, num2=", divide(num1, num2))

    ReplyDelete