Page 131 - 2622_Delhi Police Public School_C-8
P. 131

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

                     Output

                  Hello orange! How do you do?



                 Program 2: To add two numbers using all the three types of user-defined functions.


                     Program2.py
                  File  Edit  Format   Run   Options   Window    Help

                  #Type 1 Function:
                  def addl():
                      a = int(input("Enter the first number: "))
                      b = int(input("Enter the second number: "))
                      c = a + b
                      print("The sum of both the numbers is " + str(c))
                  #Type 2 Function:
                  def add2(a, b):
                      c=a+b
                      print("The sum of both the numbers is " + str(c))
                  #Type 3 Function:
                  def add3(a, b):
                      c = a + b
                      return c
                  print("Calling Type 1 function")
                  addl()
                  print("Calling Type 2 function")
                  add2(12, 16)
                  print("Calling Type 3 function")
                  result = add3(20, 30)
                  print(result)




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

                     Output

                  Calling Type 1 function
                  Enter the first number: 4
                  Enter the second number: 5
                  The sum of both the numbers is 9
                  Calling Type 2 function
                  The sum of both the numbers is 28
                  Calling Type 3 function
                  50










                                                                                   Functions and String  in Python  129
   126   127   128   129   130   131   132   133   134   135   136