{"id":32655,"date":"2021-01-25T07:00:37","date_gmt":"2021-01-25T07:00:37","guid":{"rendered":"https:\/\/samacheer-kalvi.com\/?p=32655"},"modified":"2021-12-06T15:53:01","modified_gmt":"2021-12-06T10:23:01","slug":"samacheer-kalvi-12th-computer-science-guide-chapter-7","status":"publish","type":"post","link":"https:\/\/samacheer-kalvi.com\/samacheer-kalvi-12th-computer-science-guide-chapter-7\/","title":{"rendered":"Samacheer Kalvi 12th Computer Science Guide Chapter 7 Python Functions"},"content":{"rendered":"

Tamilnadu State Board New Syllabus Samacheer Kalvi 12th Computer Science Guide<\/a> Pdf Chapter 7 Python Functions Text Book Back Questions and Answers, Notes.<\/p>\n

Tamilnadu Samacheer Kalvi 12th Computer Science Solutions\u00a0 Chapter 7 Python Functions<\/h2>\n

12th Computer Science Guide Python Functions Text Book Questions and Answers<\/h3>\n

I. Choose the best answer (I Marks)<\/span><\/p>\n

Question 1.
\nA named blocks of code that are designed to do one specific job is called as
\na) Loop
\nb) Branching
\nc) Function
\nd) Block
\nAnswer:
\nc) Function<\/p>\n

Question 2.
\nA Function which calls itself is called as
\na) Built-in
\nb) Recursion
\nc) Lambda
\nd) return
\nAnswer:
\nb) Recursion<\/p>\n

\"Samacheer<\/p>\n

Question 3.
\nWhich function is called anonymous un-named function PTA –
\na) Lambda
\nb) Recursion
\nc) Function
\nd) define
\nAnswer:
\na) Lambda<\/p>\n

Question 4.
\nWhich of the following keyword is used to begin the function block?
\na) define
\nb) for
\nc) finally
\nd) def
\nAnswer:
\nd) def<\/p>\n

\"Samacheer<\/p>\n

Question 5.
\nWhich of the following keyword is used to exit a function block?
\na) define
\nb) return
\nc) finally
\nd) def
\nAnswer:
\nb) return<\/p>\n

Question 6.
\nWhile defining a function which of the following symbol is used.
\na) ; (semicolon)
\nb) . (dot)
\nc) : (colon)
\nd) $ (dollar)
\nAnswer:
\nc): (colon)<\/p>\n

Question 7.
\nIn which arguments the correct positional order is passed to a function?
\na) Required
\nb) Keyword
\nc) Default’
\nd) Variable-length
\nAnswer:
\na) Required<\/p>\n

\"Samacheer<\/p>\n

Question 8.
\nRead the following statement and choose the correct statement(s).
\nI) In Python, you don’t have to mention the specific data types while defining function.
\nII) Python keywords can be used as function name.
\na) I is correct and II is wrong
\nb) Both are correct
\nc) I is wrong and II is correct
\nd) Both are wrong
\nAnswer:
\na) I is correct and II is wrong<\/p>\n

Question 9.
\nPick the correct one to execute the given statement successfully, if ………… : print
\n(x, ” is a leap year”)
\na) x%2=0
\nb) x%4==0
\nc) x\/4=0
\nd) x%4=0
\nAnswer:
\nb) x%4==0<\/p>\n

\"Samacheer<\/p>\n

Question 10.
\nWhich of the following keyword is used to define the function testpython(): ?
\na) define
\nb) pass
\nc) def
\nd) while
\nAnswer:
\nc) def<\/p>\n

II. Answer the following questions (2 Marks)<\/span><\/p>\n

Question 1.
\nWhat is a function?
\nAnswer:
\nFunctions are named blocks of code that are designed to do a specific job. If you need to perform that task multiple times throughout your program, you just call the function dedicated to handling that task.<\/p>\n

Question 2.
\nWrite the different types of functions.
\nAnswer:<\/p>\n

    \n
  1. User-defined functions<\/li>\n
  2. Built-in functions<\/li>\n
  3. Lambda functions<\/li>\n
  4. Recursive functions<\/li>\n<\/ol>\n

    \"Samacheer<\/p>\n

    Question 3.
    \nWhat are the main advantages of function?
    \nAnswer:<\/p>\n

      \n
    • It avoids repetition and makes high degree of code reusing.<\/li>\n
    • It provides better modularity for your application.<\/li>\n<\/ul>\n

      Question 4.
      \nWhat is meant by scope of variable? Mention its types.
      \nAnswer:<\/p>\n

        \n
      • Scope of variable refers to the part of the program, where it is accessible, i.e., area where the variables can refer (use).<\/li>\n
      • The scope holds the current set of variables and their values.<\/li>\n
      • The two types of scopes are – local scope and global scope<\/li>\n<\/ul>\n

        Question 5.
        \nDefine global scope.
        \nAnswer:
        \nA variable, with global scope can be used anywhere in the program. It can be created by defining a variable outside the scope of any function\/block.<\/p>\n

        \"Samacheer<\/p>\n

        Question 6.
        \nWhat is the base condition in a recursive function
        \nAnswer:<\/p>\n

          \n
        • A recursive function calls itself. Imagine a process would iterate indefinitely if not stopped by some condition. Such a process is known as infinite iteration.<\/li>\n
        • The condition that is applied in any recursive function is known as a base condition.<\/li>\n
        • A base condition is must in every recursive function otherwise it will continue to execute like an infinite loop.<\/li>\n<\/ul>\n

          Question 7.
          \nHow to set the limit for recursive function? Give an example.
          \nAnswer:
          \nPython also allows you to change the limit using sys.setrecursionlimit (limit value).
          \nExample:
          \nimport sys
          \nsys.setrecursionlimit(3000)
          \ndef fact (n):
          \nif n = = 0:
          \nreturn 1
          \nelse:
          \nreturn n * fact (n – 1)
          \nprint (fact (2000))<\/p>\n

          \"Samacheer<\/p>\n

          III. Answer the following questions (3 Marks)<\/span><\/p>\n

          Question 1.
          \nWrite the rules of the local variable.
          \nAnswer:<\/p>\n

            \n
          • A variable with a local scope can be accessed only within the function or block that it is created in.<\/li>\n
          • When a variable is created inside the function\/block, the variable becomes local to it.<\/li>\n
          • A local variable only exists while the function is executing.<\/li>\n
          • The format arguments are also local to function.<\/li>\n<\/ul>\n

            Question 2.
            \nWrite the basic rules for a global keyword in python.
            \nAnswer:<\/p>\n

              \n
            • When we define a variable outside a function, it’s global by default. We don’t have to use the global keyword.<\/li>\n
            • We use a global keyword to read and write a global variable inside a function.<\/li>\n
            • Use of global keyword outside a function has no effect.<\/li>\n<\/ul>\n

              \"Samacheer<\/p>\n

              Question 3.
              \nWhat happens when we modify the global variable inside the function?
              \nAnswer:
              \nIt will change the global variable value outside the function also.<\/p>\n

              Question 4.
              \nDifferentiate ceil() and floor() function?<\/p>\n\n\n\n\n
              \n

              Cell()<\/p>\n<\/td>\n

              \n

              Floor ()<\/p>\n<\/td>\n<\/tr>\n

              ceil () returns the smallest integer greater than or equal to the given value.<\/td>\nfloor() returns the largest integer less than or equal to the given value.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

              Question 5.
              \nWrite a Python code to check whether a given year is leap year or not
              \nAnswer:
              \nn = int (input(“Enter any year”))
              \nif (n % 4 = = 0):
              \nprint “Leap year”
              \nelse:
              \nprint “Not a Leap year”
              \nOutput:
              \nEnter any year 2001
              \nNot a Leap year<\/p>\n

              \"Samacheer<\/p>\n

              Question 6.
              \nWhat is a composition in functions?
              \nAnswer:<\/p>\n

                \n
              • The value returned by a function may be used as an argument for another function in a nested manner is called composition.<\/li>\n
              • For example, if we wish to take a numeric value or an expression as a input from the user, we take the input string from the user using the function input() and apply eval() function to evaluate its value<\/li>\n<\/ul>\n

                Question 7.
                \nHow recursive function works?
                \nAnswer:<\/p>\n

                  \n
                • Recursive function is called by some external code.<\/li>\n
                • If the base condition is met then the program gives meaningful output and exits.<\/li>\n
                • Otherwise, the function does some required processing and then calls itself to continue recursion.<\/li>\n<\/ul>\n

                  Question 8.
                  \nWhat are the points to be noted while defining a function?
                  \nAnswer:<\/p>\n

                    \n
                  • Function blocks begin with the keyword \u201cdef\u201dfollowed by function name and parenthesis() .<\/li>\n
                  • Any input parameters or arguments should be placed within these parentheses when you define a function.<\/li>\n
                  • The code block always comes after colon(;) and is indented.<\/li>\n
                  • The statement “return [expression]” exits a function, optionally passing back an expression to the caller.<\/li>\n
                  • A “return” with no arguments is the same as return None.<\/li>\n<\/ul>\n

                    \"Samacheer<\/p>\n

                    IV. Answer the following questions (5 Marks)<\/span><\/p>\n

                    Question 1.
                    \nExplain the different types of function with an example.
                    \nAnswer:<\/p>\n\n\n\n\n\n\n\n
                    \n

                    Functions<\/p>\n<\/td>\n

                    \n

                    Description<\/p>\n<\/td>\n<\/tr>\n

                    User-defined functions<\/td>\nFunctions defined by the users themselves<\/td>\n<\/tr>\n
                    Built-in functions<\/td>\nFunctions that are inbuilt within Python.<\/td>\n<\/tr>\n
                    Lambda functions<\/td>\nFunctions that are anonymous un-named function.<\/td>\n<\/tr>\n
                    Recursive functions<\/td>\nFunctions that call themselves is known as recursive.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

                    1. User-defined function:
                    \nFunctions defined by the users themselves are called User-defined functions.
                    \nSyntax:
                    \ndef :
                    \n< Block of statement >
                    \nreturn < expression \/ None>
                    \nExample:
                    \ndef welcome():
                    \nprint(“Welcome to Python”)
                    \nreturn<\/p>\n

                    2. Built-in functions:
                    \nFunctions which are using Python libraries are called Built-in functions.
                    \nExample:
                    \nx=20
                    \ny=-23
                    \nprint(‘First number = ” ,x)
                    \nprint(‘Second number = ” ,y)
                    \nOutput:
                    \nFirst number = 20
                    \nSecond number = 23
                    \n3. Lambda function:<\/p>\n

                      \n
                    • Lambda function is mostly used for creating small and one-time anonymous function.<\/li>\n
                    • Lambda functions are mainly used in combination with the functions like filter]), map]) and reduce]).
                      \nSyntax of Lambda function (Anonymous Functions):
                      \nlambda [argument(s)]: expression<\/li>\n<\/ul>\n

                      Example:
                      \nsum = lambda arg1, arg2: arg1 + arg2
                      \nprint (The Sum is :’, sum(30, 40)
                      \nprint (The Sum is sum(-30, 40)<\/p>\n

                      Output:
                      \nThe Sum is: 70
                      \nThe Sum is: 10<\/p>\n

                      4. Recursive function:<\/p>\n

                        \n
                      • A recursive function calls itself. Imagine a process would iterate indefinitely if not stopped by some condition! Such a process is known as infinite iteration.<\/li>\n
                      • The condition that is applied in any recursive function is known as a base condition.<\/li>\n
                      • A base condition is must in every recursive function otherwise it will continue to execute like an infinite loop.<\/li>\n
                      • Overview of how recursive function works:<\/li>\n
                      • Recursive function is called by some external code.<\/li>\n
                      • If the base condition is met then the. program gives meaningful output and exits.<\/li>\n
                      • Otherwise, function does some required processing and then calls itself to continue recursion.
                        \nHere is an example of recursive function used to calculate factorial.<\/li>\n<\/ul>\n

                        Example:
                        \ndef fact(n):
                        \nif n==0:
                        \nreturn 1
                        \nelse:
                        \nreturn n * fact (n-1)
                        \nprint (fact (0))
                        \nprint (fact (5))<\/p>\n

                        Output:
                        \n1
                        \n120<\/p>\n

                        \"Samacheer<\/p>\n

                        Question 2.
                        \nExplain the scope of variables with an example.
                        \nAnswer:
                        \nScope of Variables:
                        \nScope of variable refers to the part of the program, where it is accessible, i.e., an area where you can refer (use) it. We can say that scope holds the current set of variables and their values.
                        \nThe two types of scopes are local scope and global scope.<\/p>\n

                        (I) Local scope:
                        \nA variable declared inside the function’s body or in the local scope is called a local variable.<\/p>\n

                        Rules of local variable:<\/p>\n

                          \n
                        1. A variable with local scope can be accessed only within the function\/block that it is created in.<\/li>\n
                        2. When a variable is created inside the function\/block; the variable becomes local to it.<\/li>\n
                        3. A local variable only exists while the function is executing.<\/li>\n
                        4. The formate arguments are also local to function.<\/li>\n<\/ol>\n

                          Example: Create a Local Variable
                          \ndef loc ( ):
                          \ny = 0 # local scope
                          \nprint (y)
                          \nloc ( )
                          \nOutput:
                          \n0
                          \n(II) Global Scope:
                          \nA variable, with global scope can be used anywhere in the program. It can be created by defining a variable outside the scope of any function\/block.<\/p>\n

                          Rules of global Keyword:
                          \nThe basic rules for global keyword in Python are:<\/p>\n

                            \n
                          1. When we define a variable outside a function, it\u2019s global by default. You don\u2019t have to useglobal keyword.<\/li>\n
                          2. We use global keyword to read and write a global variable inside a function.<\/li>\n
                          3. Use of global keyword outside a function has no effect<\/li>\n<\/ol>\n

                            Example: Global variable and Local variable with same name
                            \nx = 5 def loc ( ):
                            \nx = 10
                            \nprint (“local x:”, x)
                            \nloc ( )
                            \nprint (“global x:”, x)
                            \nOutput:
                            \nlocal x: 10
                            \nglobal x: 5
                            \nIn the above code, we used same name \u2018x\u2019 for both global variable and local variable. We get a different result when we print same variable because the variable is declared in both scopes, i.e. the local scope inside the function loc() and global scope outside the function loc ( ).
                            \nThe output:- local x: 10, is called local scope of variable.
                            \nThe output: – global x: 5, is called global scope of variable.<\/p>\n

                            \"Samacheer<\/p>\n

                            Question 3.
                            \nExplain the following built-in functions.
                            \nAnswer:
                            \na) id()
                            \nb) chr()
                            \nc) round ()
                            \nd) type()
                            \ne) pow()
                            \n\"Samacheer
                            \n\"Samacheer<\/p>\n

                            Question 4.
                            \nWrite a Python code to find the L.C.M. of two numbers.
                            \nAnswer:
                            \nProgram:
                            \n# Python Program to find the L.C.M. of two input number
                            \ndefcompute_lcm(x, y):
                            \n# choose the greater number
                            \nif x > y:
                            \ngreater = x
                            \nelse:
                            \ngreater = y
                            \nwhile (True):
                            \nif((greater % x == 0) and (greater % y == 0)):
                            \n1cm = greater
                            \nbreak
                            \ngreater += 1
                            \nreturn 1cm
                            \nnum1=int(input(\/\/Enter first number=”))
                            \nnum2=int(input(“Enter second number=”))
                            \nprint
                            \n(“The L.C.M. is”, compute_lcm(num1, num2))
                            \nOutput:
                            \nEnter first number=8
                            \nEnter second number=4
                            \nThe L.C.M. is 8<\/p>\n

                            \"Samacheer<\/p>\n

                            Question 5.
                            \nExplain the recursive function with an example.
                            \nAnswer:
                            \nPython recursive functions
                            \nWhen a function calls itself is known as recursion. Recursion works like loop but sometimes it makes more sense to use recursion than loop. You can convert any loop to recursion.
                            \nA recursive function calls itself. Imagine a process would iterate indefinitely if not stopped by some condition! Such a process is known as infinite iteration. The condition that is applied in any recursive function is known as base condition. A base condition is must in every recursive function otherwise it will continue to execute like an infinite loop.<\/p>\n

                            Working Principle:<\/p>\n

                              \n
                            1. Recursive function is called by some external code.<\/li>\n
                            2. If the base condition is met then the program gives meaningful output and exits.<\/li>\n
                            3. Otherwise, function does some required processing and then calls itself to continue recursion. Here is an example of recursive function used to calculate factorial.<\/li>\n<\/ol>\n

                              Example:
                              \ndef fact (n):
                              \nif n = = 0:
                              \nreturn 1
                              \nelse:
                              \nreturn n * fact (n – 1)
                              \nprint (fact (0))
                              \nprint (fact (5))
                              \nOutput:
                              \n1
                              \n120<\/p>\n

                              \"Samacheer<\/p>\n

                              12th Computer Science Guide Python Functions Additional Questions and Answers<\/h3>\n

                              I. Choose the best answer<\/span><\/p>\n

                              Question 1.
                              \nThe name of the function is followed by ………………………….
                              \n(a) ( )
                              \n(b) [ ]
                              \n(c) <>
                              \n(d) { }
                              \nAnswer:
                              \n(a) ( )<\/p>\n

                              Question 2.
                              \nWhich of the following provides better modularity for your python application
                              \na) tuples
                              \nb) function
                              \nc) dictionaries
                              \nd) control structures
                              \nAnswer:
                              \nb) function.<\/p>\n

                              \"Samacheer<\/p>\n

                              Question 3.
                              \nHow many types of functions are there in python?
                              \na) 3
                              \nb) 2
                              \nc) 4
                              \nd) 5
                              \nAnswer:
                              \nc) 4<\/p>\n

                              Question 4.
                              \nFunctions that call itself are known as
                              \na) User-defined
                              \nb) Built-in
                              \nc) Recursive
                              \nd) Lambda
                              \nAnswer:
                              \nc) Recursive<\/p>\n

                              Question 5.
                              \nIf the return has no argument, …………………………….. will be displayed as the last statement of the output.
                              \n(a) No
                              \n(b) None
                              \n(c) Nothing
                              \n(d) No value
                              \nAnswer:
                              \n(b) None<\/p>\n

                              \"Samacheer<\/p>\n

                              Question 6.
                              \nIn which of the following the number of arguments in the function call should match exactly with the function definition?
                              \na) Keyword arguments
                              \nb) Required arguments
                              \nc) Default arguments
                              \nd) Variable-length arguments
                              \nAnswer:
                              \nb) Required arguments<\/p>\n

                              Question 7.
                              \nWhich of the following is used to define variable-length arguments?
                              \na) $
                              \nb) *
                              \nc) #
                              \nd) \/\/
                              \nAnswer:
                              \nb) *<\/p>\n

                              \"Samacheer<\/p>\n

                              Question 8.
                              \nWhat is the symbol used to denote variable-length arguments?
                              \n(a) +
                              \n(b) *
                              \n(c) &
                              \n(d) ++
                              \nAnswer:
                              \n(b) *<\/p>\n

                              Question 9.
                              \nWhich function can take any number of arguments and must return one value in the form of an expression?
                              \na) user-defined
                              \nb) recursive
                              \nc) default
                              \nd) lambda
                              \nAnswer:
                              \nd) lambda<\/p>\n

                              \"Samacheer<\/p>\n

                              Question 10.
                              \nHow many return statement is executed at runtime?
                              \na) 2
                              \nb) multiple
                              \nc) 3
                              \nd) 1
                              \nAnswer:
                              \nd) 1<\/p>\n

                              Question 11.
                              \nHow many types of scopes in Python?
                              \na) 3
                              \nb) 4
                              \nc) many
                              \nd) 2
                              \nAnswer:
                              \nd) 2<\/p>\n

                              Question 12.
                              \nLambda functions cannot be used in combination with ………………………….
                              \n(a) Filter
                              \n(b) Map
                              \n(c) Print
                              \n(d) Reduce
                              \nAnswer:
                              \n(c) Print<\/p>\n

                              \"Samacheer<\/p>\n

                              Question 13.
                              \nFunction blocks begin with the keyword …………………
                              \na) Fun
                              \nb) Definition
                              \nc) Function
                              \nd) Def
                              \nAnswer:
                              \nd) Def<\/p>\n

                              Question 14.
                              \n………………. function can only access global variables.
                              \na) user-defined
                              \nb) recursive
                              \nc) Lambda
                              \nd) return
                              \nAnswer:
                              \nc) Lambda<\/p>\n

                              \"Samacheer<\/p>\n

                              Question 15.
                              \nFind the correct one:
                              \n(a) Global keyword outside the function has no effect
                              \n(b) Global keyword outside the function has an effect
                              \nAnswer:
                              \n(a) Global keyword outside the function has no effect<\/p>\n

                              II. Answer the following questions (2 and 3 Marks)<\/span><\/p>\n

                              Question 1.
                              \nDefine nested blocks?
                              \nAnswer:
                              \nNested Block:
                              \nA block within a block is called a nested block. When the first block statement is indented by a single tab space, the second block of statement is indented by double tab spaces.<\/p>\n

                              Question 2.
                              \nDifferentiate parameters and arguments.
                              \nAnswer:<\/p>\n\n\n\n\n
                              \n

                              Parameters<\/p>\n<\/td>\n

                              \n

                              Arguments<\/p>\n<\/td>\n<\/tr>\n

                              Parameters are the variables used in the function definition.<\/td>\nArguments are the values we pass to the function parameters.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

                              \"Samacheer<\/p>\n

                              Question 3.
                              \nDifferentiate parameters and arguments?
                              \nAnswer:
                              \nParameters are the variables used in the function definition whereas arguments are the values we pass to the function parameters.<\/p>\n

                              Question 4.
                              \nWrite the syntax of variable-length arguments.
                              \nAnswer:
                              \ndef function_name(*args):
                              \nfunction_body
                              \nreturn_statement<\/p>\n

                              Question 5.
                              \nWhat are the methods used to parse the arguments to the variable length arguments?
                              \nAnswer:
                              \nIn Variable Length arguments, we can parse the arguments using two methods.<\/p>\n

                                \n
                              • Non-keyword variable arguments<\/li>\n
                              • Keyword variable arguments<\/li>\n<\/ul>\n

                                \"Samacheer<\/p>\n

                                Question 6.
                                \nWhat is a local variable?
                                \nAnswer:
                                \nA variable declared inside the function’s body or in the local scope is known as a local variable.<\/p>\n

                                Question 7.
                                \nWhat are the two methods of passing arguments in variable-length arguments?
                                \nAnswer:
                                \nIn Variable Length arguments, we can pass the arguments using two methods.<\/p>\n

                                  \n
                                1. Non-keyword variable arguments<\/li>\n
                                2. Keyword variable arguments<\/li>\n<\/ol>\n

                                  Question 8.
                                  \nWrite a note on return statement?
                                  \nAnswer:
                                  \nThe return Statement<\/p>\n

                                    \n
                                  1. The return statement causes your function to exit and returns a value to its caller. The point of functions in general is to take inputs and return something.<\/li>\n
                                  2. The return statement is used when a function is ready to return a value to its caller. So, only one return statement is executed at run time even though the function contains multiple return statements.<\/li>\n
                                  3. Any number of ‘return’ statements are allowed in a function definition but only one of them is executed at run time.<\/li>\n<\/ol>\n

                                    \"Samacheer<\/p>\n

                                    Question 9.
                                    \nWrite a note on min (), max () and sum () with an example
                                    \nAnswer:
                                    \nFunction: min ()
                                    \nDescription: Returns the minimum value in a list.
                                    \nSyntax: min (list)
                                    \nExample:
                                    \nMy List = [21,76,98,23]
                                    \nprint (‘Minimum of My List:’,
                                    \nmin(My List))
                                    \nOutput:
                                    \nMinimum of My List: 21
                                    \nFunction.: max ()
                                    \nDescription:
                                    \nReturns the maximum value in a list.
                                    \nSyntax : min (list)
                                    \nExample:
                                    \nMy List = [21,76,98,23]
                                    \nprint (\u2018maximum of My List :\u2018, max
                                    \n(my list)
                                    \nOutput:
                                    \nMaximum of My List: 98
                                    \nFunction : sum ()
                                    \nDescription:
                                    \nReturns the sum of values in a list.
                                    \nSyntax :sum (list)
                                    \nExample:
                                    \nMy List = [21,76,98,23]
                                    \nprint (Sum of My List :\u2018, sum(My List))
                                    \nOutput:
                                    \nSum of My List :218<\/p>\n

                                    \"Samacheer<\/p>\n

                                    Question 10.
                                    \nWrite a note on the floor, cell () and sqrt () with an example
                                    \nAnswer:
                                    \nFunction: floor ()
                                    \nDescription: Returns the largest integer
                                    \nless than or equal to x.
                                    \nSyntax: math.floor (x)
                                    \nExample:
                                    \nx=26.7
                                    \ny=-26.7
                                    \nprint (math.floor (x))
                                    \nprint (math.floor (y))
                                    \nOutput:
                                    \n26
                                    \n-27
                                    \nFunction: ceil ()
                                    \nDescription: Returns the smallest integer greater than or equal to x.
                                    \nSyntax: math.ceil (x)
                                    \nExample:
                                    \nx=26.7
                                    \ny=-26.7
                                    \nprint (math.ceil (x))
                                    \nprint (math.ceil (y))
                                    \nOutput:
                                    \n27
                                    \n-26 . ‘
                                    \nFunction : sqrt ()
                                    \nDescription: Returns the square root of x (Note: x must be greater than zero) Syntax: sqrt (x)
                                    \nExample:
                                    \na=49
                                    \nb= 25
                                    \nprint (math.sqrt (a))
                                    \nprint (math.sqrt (b))
                                    \nOutput:
                                    \n7.0
                                    \n5.0<\/p>\n

                                    \"Samacheer<\/p>\n

                                    Question 11.
                                    \nWrite a note on the format () with an example.
                                    \nAnswer:
                                    \nFunction: format ()
                                    \nDescription:
                                    \nReturns the output based on the given format.<\/p>\n

                                      \n
                                    • Binary format: Outputs the number in base 2.<\/li>\n
                                    • Octal format: Outputs the number in base 8.<\/li>\n
                                    • Fixed-point notation: Displays the number as a fixed-point number. The default precision is 6.<\/li>\n<\/ul>\n

                                      Syntax : format (value [\u201aformat_spec])
                                      \nExample:
                                      \nx=14
                                      \ny=25
                                      \nprint (‘x value in binary :’,format(x\/b’))
                                      \nprint (‘y value in octal ^formatfy\/o’))
                                      \nprint(‘y value in Fixed-point no ‘,format(y\/f’))
                                      \nOutput:
                                      \nx value in binary: 1110
                                      \ny value in octal: 31
                                      \ny value in Fixed-point no : 25.000000<\/p>\n

                                      \"Samacheer<\/p>\n

                                      III. Answer the following questions (5 Marks)<\/span><\/p>\n

                                      Question 1.
                                      \nExplain different types of arguments used in python with an example.
                                      \nAnswer:<\/p>\n

                                        \n
                                      • Arguments are used to call a function.<\/li>\n
                                      • There are primarily four types of functions namely:
                                        \n1. Required arguments
                                        \n2. Keyword arguments,
                                        \n3. Default arguments
                                        \n4. Variable-length arguments.<\/li>\n<\/ul>\n

                                        Required Arguments:<\/p>\n

                                          \n
                                        • \u201cRequired Arguments\u201d are the arguments passed to a function in correct positional order.<\/li>\n
                                        • The number of arguments in the function call should match exactly with the function definition.<\/li>\n
                                        • Atleast one parameter to prevent syntax errors to get the required output.<\/li>\n<\/ul>\n

                                          Example:
                                          \ndefprintstring(str):
                                          \nprint (\u201cExample – Required arguments\u201d)
                                          \nprint (str)
                                          \nreturn
                                          \n# Now you can call printstring() function
                                          \nprintstring (\u201cWelcome\u201d)<\/p>\n

                                          Output:
                                          \nExample – Required arguments Welcome
                                          \nWhen the above code is executed, it
                                          \nproduces the following error.
                                          \nTraceback (most recent call last):
                                          \nFile “Req-arg.py”, line 10, in < module >
                                          \nprintstring()
                                          \nTypeError: printstring() missing 1
                                          \nrequired positional argument: ‘str’
                                          \nInstead of printstring() in the above code if we use printstring (“Welcome”) then the output is
                                          \nOutput:
                                          \nExample – Required arguments Welcome<\/p>\n

                                          Keyword Arguments:<\/p>\n

                                            \n
                                          • Keyword arguments will invoke the function after the parameters are recognized by their parameter names.<\/li>\n
                                          • The value of the keyword argument is matched with the parameter name and so, one can also put arguments in improper order (not in order).<\/li>\n<\/ul>\n

                                            Example:
                                            \ndef printdata (name):
                                            \nprint (“Example-1 Keyword arguments”)
                                            \nprint (“Name : “:name)
                                            \nreturn
                                            \n# Now you can call printdatat() function
                                            \nprint data(name = “Gshan”) When the above code is executed, it produces the following output:<\/p>\n

                                            Output:
                                            \nExample-1 Keyword arguments
                                            \nName: Gshan
                                            \nDefault Arguments:<\/p>\n

                                              \n
                                            • In Python the default argument is an argument that takes a default value if no value is provided in the function call.<\/li>\n
                                            • The following example uses default arguments, that prints default salary when no argument is passed.<\/li>\n<\/ul>\n

                                              Example:
                                              \ndef printinfo( name, salary = 3500):
                                              \nprint (“Name:”, name)
                                              \nprint (“Salary: “, salary)
                                              \nreturn
                                              \nprintinfo(“Mani”)
                                              \nWhen the above code is executed, it produces the following output<\/p>\n

                                              Output:
                                              \nName: Mani
                                              \nSalary: 3500
                                              \nWhen the above code is changed as print info(“Ram,”:2000) it produces the following<\/p>\n

                                              Output:
                                              \nName: Ram
                                              \nSalary: 2000<\/p>\n

                                              Variable-Length Arguments:<\/p>\n

                                                \n
                                              • In some instances, it is needed to pass more arguments that have already been specified.<\/li>\n
                                              • These arguments are not specified in the function’s definition and an asterisk (*) is used to define such arguments.<\/li>\n
                                              • These types of arguments are called Variable-Length arguments.<\/li>\n<\/ul>\n

                                                Syntax:
                                                \ndef function_name(*args):
                                                \nfunction_body
                                                \nreturn_statement<\/p>\n

                                                Example:
                                                \ndef printnos (*nos):
                                                \nfor n in nos:
                                                \nprint(n)
                                                \nreturn
                                                \n# now invoking the printnos() function
                                                \nprint (‘Printing two values’)
                                                \nprintnos (1,2)
                                                \nPrint (‘Printing three values’)
                                                \nprintnos (10,20,30)<\/p>\n

                                                Output:
                                                \nPrinting two values
                                                \n1
                                                \n2
                                                \nPrinting three values
                                                \n10
                                                \n20
                                                \n30<\/p>\n","protected":false},"excerpt":{"rendered":"

                                                Tamilnadu State Board New Syllabus Samacheer Kalvi 12th Computer Science Guide Pdf Chapter 7 Python Functions Text Book Back Questions and Answers, Notes. Tamilnadu Samacheer Kalvi 12th Computer Science Solutions\u00a0 Chapter 7 Python Functions 12th Computer Science Guide Python Functions Text Book Questions and Answers I. Choose the best answer (I Marks) Question 1. A …<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[5],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/samacheer-kalvi.com\/wp-json\/wp\/v2\/posts\/32655"}],"collection":[{"href":"https:\/\/samacheer-kalvi.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/samacheer-kalvi.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/samacheer-kalvi.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/samacheer-kalvi.com\/wp-json\/wp\/v2\/comments?post=32655"}],"version-history":[{"count":1,"href":"https:\/\/samacheer-kalvi.com\/wp-json\/wp\/v2\/posts\/32655\/revisions"}],"predecessor-version":[{"id":47682,"href":"https:\/\/samacheer-kalvi.com\/wp-json\/wp\/v2\/posts\/32655\/revisions\/47682"}],"wp:attachment":[{"href":"https:\/\/samacheer-kalvi.com\/wp-json\/wp\/v2\/media?parent=32655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/samacheer-kalvi.com\/wp-json\/wp\/v2\/categories?post=32655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/samacheer-kalvi.com\/wp-json\/wp\/v2\/tags?post=32655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}