Page 125 - Code_GPT_Class_8
P. 125

Program 13: To add two numbers using function.

                     Program13.py
                  File  Edit  Format   Run   Options   Window    Help

                  def add(a, b):
                      sum = a * b
                      return sum
                  numl = int(input("Enter first number: "))
                  num2 = int(input("Enter second number: "))
                  print("The sum is",add(numl,num2))




                 On running the above program, you will get the following output:

                     Output

                  Enter first number: 5
                  Enter second number: 6
                  The sum is 11




                 Program 14: To find the product of two numbers using function.


                     Program14.py
                  File  Edit  Format   Run   Options   Window    Help


                  def prod(a, b):
                      multi = a * b
                      return multi
                  numl = int(input("Enter first number: "))
                  num2 = int(input("Enter second number: "))
                  print("The product is",prod(numl,num2))





                 On running the above program, you will get the following output:

                     Output

                  Enter first number: 5
                  Enter second number: 4
                  The sum is 20













                                                                                   Functions and String  in Python  123
   120   121   122   123   124   125   126   127   128   129   130