56 solutions available
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 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 9Fill in the line of code for calculating the factorial of a number:def fact(num): if num == 0: return 1 else:...
Question 11What is the output of the following snippet?def fun(n): if (n > 100): return n - 5 return fun (fun (n+11) )...
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 5What is the utility of:Default argumentsKeyword arguments
Question 6Describe the different types of functions in Python using appropriate examples.
Question 8What is the difference between local and global variables?
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 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...