Page 96 - 2611_SmartGPT Pro V(5.0) C-8
P. 96

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





                            STRING


                  A sequence of characters which is enclosed or surrounded by single (‘ ’), double (“ ”), or tipple (“‘ ’”)
                  quotes is known as a string. The sequence may include a letter, number, special characters or a
                  backslash. Python treats single quotes as double quotes.






                   94   Computer Science (V5.0)-VIII
   91   92   93   94   95   96   97   98   99   100   101