101 solutions available
Question 1Assertion (A): Function can take input values as parameters, execute them and return output (if required) to the calling function with a...
Question 2Assertion (A): If the arguments in a function call statement match the number and order of arguments as defined in the function definition,...
Question 3Assertion (A): Local Variables are accessible only within a function or block in which they are declared.Reasoning (R): Global variables...
Question 4Assertion (A): The local and global variables declared with the same name in the function are treated in the same manner by the Python...
Question 5Assertion (A): The functions developed and defined by language programmers and provided within the framework of the language are termed as...
Question 6Assertion (A): To use positional arguments, the arguments need to be passed in the same order as their respective parameters in the...
Question 1A set of instructions/operations which is a part of a program and can be executed independently to do specific task is called a function.
Question 2Python passes parameters by value.
Question 3The variable declared outside all the functions is called a global variable.
Question 4The order in which statements are executed during a program run is called the flow of execution.
Question 5A module is a file containing Python definitions and statements intended for use in other Python programs.
Question 6Functions that do not explicitly return a value return the special object None.
Question 7The first line of a function definition is called function header.
Question 8The function which is written by the programmer as per his/her requirements is known as user-defined function.
Question 9A function is said to be recursive if it calls itself.
Question 10Arguments/Parameters act as a means of communication between the called and calling function.
Question 11The scope of a variable is the area of the program where it may be referenced.
Question 12The terminating condition used for solving a problem using recursion is termed as the base case for that problem.
Question 13def keyword is used to define a function.
Question 14Function name must be followed by () (Parenthesis) and : (colon).
Question 1A function in Python begins with which keyword?voidreturnintdef
Question 2Name the statement that sends back a value from a function.printinputreturnNone
Question 3Functions that do not return any value are known as:fruitful functionsvoid functionslibrary functionsuser-defined functions
Question 4A variable created or defined within a function body is classified as:localglobalbuilt-ininstance
Question 5Which of the following arguments works with implicit values that are used if no value is provided?keywordrequiredvariable-lengthdefault
Question 6Which values are used by the functions to communicate information back to the caller?localglobalreturnrandom
Question 7What is the output of the program given below?x = 50 def func(x): x = 2 func(x) print('x is now', x)x is now 50x is now 2x is now...
Question 8Which is the most appropriate definition for recursion?A function that calls itselfA function execution instance that calls another...
Question 9Fill in the line of code for calculating the factorial of a number:def fact(num): if num == 0: return 1 else:...
Question 10Which of the following statements is false about recursion?Every recursive function must have a base case.Infinite recursion can occur if...
Question 11What is the output of the following snippet?def fun(n): if (n > 100): return n - 5 return fun (fun (n+11) )...
Question 12What happens if the base condition isn't defined in recursive programs?Program gets into an infinite loopProgram runs onceProgram runs n...
Question 1A program having multiple functions is considered better designed than a program without any functions. Why?
Question 2Write a function called calculate_area() that takes base and height as input arguments and returns area of a triangle as an output. The...
Question 3Modify the above function to take a third parameter called shape type. Shape type should be either triangle or rectangle. Based on the...
Question 4Write a function called print_pattern() that takes integer number as argument and prints the following pattern if the input number is 3.*...
Question 5What is the utility of:Default argumentsKeyword arguments
Question 6Describe the different types of functions in Python using appropriate examples.
Question 7What is scope? What is the scope-resolving rule of Python?
Question 8What is the difference between local and global variables?
Question 9Write the term suitable for the following descriptions:(a) A name inside the parentheses of a function header that can receive a value.(b)...
Question 10Consider the following code and write the flow of execution for this. Line numbers have been given for our reference.1. def power(b, p):...
Question 11What will the following function return?def addEm(x, y, z): print(x + y + z) x = y = z = 10
Question 12What will be the output displayed when addEM() is called/executed?def addEM(x, y, z): return x + y + z x=y=z=20
Question 13(i)What will be the output of the following program?num = 1 def myfunc() : return num print (num) print (myfunc()) print (num)
Question 13(ii)What will be the output of the following program?num = 1 def myfunc() : num = 10 return num print (num) print (myfunc())...
Question 13(iii)What will be the output of the following program?num = 1 def myfunc(): global num num = 10 print (num) print (myfunc())...
Question 13(iv)What will be the output of the following program?def display(): print ("Hello",) display() print("bye!")
Question 14What is wrong with the following function definition?def addEm(x, y, z ): return x + y + z print("the answer is :", x + y + z)
Question 15Predict the output of the following code:a = 10 y = 5 def myfunc (a) : y = a a = 2 print ("y=",y, "a=", a) print ("a+y",...
Question 16(a)Find the errors in the code given below:def minus (total, decrement) output = total - decrement print (output) return...
Question 16(b)Find the errors in the code given below:define check() N = input ( 'Enter N:'_ I = 3 Answer = 1 + i ** 4/N Return answer
Question 17Define flow of execution. What does it do with functions?
Question 18Write a function that takes amount-in-dollars and dollar-to-rupee conversion price; it then returns the amount converted to rupees. Create...
Question 19Write a function to calculate volume of a box with appropriate default values for its parameters. Your function should have the following...
Question 20Write a program to display first four multiples of a number using recursion.Solutiondef display_multiples(n, count = 1): if count >...
Question 21What do you understand by recursion ? State the advantages and disadvantages of using recursion.
Question 22Write a recursive function to add the first 'n' terms of the series:1 + 1/2 - 1/3 + 1/4 - 1/5...............Solutiondef...
Question 23Write a program to find the greatest common divisor between two numbers.Solutiondef gcd(a, b): while b: a, b = b, a % b...
Question 24Write a Python function to multiply all the numbers in a list.Sample List: (8, 2, 3, -1, 7)Expected Output : -336Solutiondef...
Question 25Write a Python function to calculate the factorial of a number (a non-negative integer). The function accepts the number whose factorial...
Question 26Write a Python function that takes a number as a parameter and checks whether the number is prime or not.Solutiondef is_prime(n): if n...
Question 27Write a Python function that checks whether a passed string is a palindrome or not.Note: A palindrome is a word, phrase, or sequence that...
Question 28Write a Python program that accepts a hyphen-separated sequence of words as input and prints the words in a hyphen-separated sequence...
Question 29What is a recursive function? Write one advantage of recursive function.
Question 30What are the two cases required in a recursive function?
Question 31What is base case?
Question 32What is recursive case?
Question 33Is it necessary to have a base case in a recursive function? Why/Why not?
Question 34Identify the base case(s) in the following recursive function:def function1(n): if n == 0: return 5 elif n == 1:...
Question 35Why are recursive functions considered slower than their iterative counterparts?
Question 36Compare and contrast the use of iteration and recursion in terms of memory space and speed.
Question 37(a)Predict the output of the following code.def code(n): if n == 0: print ( 'Finally' ) else: print (n) code (3)...
Question 37(b)Predict the output of the following code.def code (n) : if n==0: print('Finally') else: print(n) code (2-2) code...
Question 37(c)Predict the output of the following code.def code(n): if n == 0: print(' Finally') else: print (n) code (10)
Question 37(d)Predict the output of the following code.def code (n) : if n==0: print ( 'Finally' ) else: print (n)...
Question 38Predict the output of the following code:def express (x, n) : if n == 0: return 1 elif n % 2 == 0: return express...
Question 39Consider the following Python function that uses recursion.def check (n) : if n <=1: return True elif n % 2 == 0:...
Question 40Can you find an error or problem with the below code? Think about what happens if we evaluate check(3). What output would be produced by...
Question 41Consider the following Python function Fn(), that follows:def Fn(n): print (n, end=" ") if n < 3: return n else:...
Question 42Figure out the problem with the following code that may occur when it is run.def recur(p): if p == 0: print ("##") else:...
Question 43Write a method in Python to find and display the prime numbers from 2 to N. The value of N should be passed as an argument to the...
Question 44Write a method EvenSum(NUMBERS) to add those values in the tuple of NUMBERS which are even.Solutiondef EvenSum(NUMBERS): even_sum = 0...
Question 45Write a method COUNTNOW(PLACES) to find and display those place names in which there are more than 5 characters after storing the name of...
Question 46Write a program using user-defined function to calculate and display average of all the elements in a user-defined tuple containing...
Question 47Name the built-in mathematical function/method:(a) Used to return an absolute value of a number.(b) Used to return the value of xy, where...
Question 48Name the built-in String function:(a) Used to remove the space(s) from the left of the string.(b) Used to check if the string is uppercase...
Question 49Write a function LeftShift(lst, x) in Python which accepts numbers in a list (lst) and all the elements of the list should be shifted to...
Question 1More than one value(s) can be returned by a function in Python.
Question 2The variable declared inside a function is called a global variable.
Question 3Once a function is defined, it may be called only once from many different places in a program.
Question 4Value returning functions should be generally called from inside of an expression.
Question 5A local variable having the same name as that of a global variable hides the global variable in its function.
Question 6In Python, function arguments are required and we cannot define a function without them.
Question 7Parameters specified within a pair of parentheses in the function definition are the actual parameters or non-formal parameters.
Question 8A function in Python is used by invoking it via a function call.
Question 9Built-in functions are created by users and are not a part of the Python library.
Question 10The first line of a function header begins with def keyword and eventually ends with a colon (:).
Question 11Recursive functions are faster than their iterative counterparts.
Question 12Recursion is defined as defining anything in terms of itself.
Question 13Function can alter only mutable data types.