On This Page

This set of Problem Solving and Python Programming Multiple Choice Questions & Answers (MCQs) focuses on Problem Solving And Python Programming Set 11

Q1 | Which of the following data structures is returned by the functions globals() and locals()?
  • list
  • set
  • dictionary
  • tuple
Q2 | On assigning a value to a variable inside a function, it automatically becomes a global variable.
  • true
  • false
Q3 | What happens if a local variable exists with the same name as the global variable you want to access?
  • error
  • the local variable is shadowed
  • undefined behavior
  • the global variable is shadowed
Q4 | print(a)
  • 10
  • 25
  • junk value
  • error
Q5 | f() x
  • error
  • 4
  • junk value
  • 1
Q6 | Which is the most appropriate definition for recursion?
  • a function that calls itself
  • a function execution instance that calls another execution instance of the same function
  • a class method that calls another class method
  • an in-built method that is automatically called
Q7 | Only problems that are recursively defined can be solved using recursion.
  • true
  • false
Q8 | Which of these is false about recursion?
  • recursive function can be replaced by a non-recursive function
  • recursive functions usually take more memory space than non-recursive function
  • recursive functions run faster than non- recursive function
  • recursion makes programs easier to understand
Q9 | ,i+j) print(test(4,7))
  • 13
  • 7
  • infinite loop
  • 17
Q10 | 5 RECURSION
  • 011
  • 110
  • 3
  • infinite loop
Q11 | What is tail recursion?
  • a recursive function that has two base cases
  • a function where the recursive functions leads to an infinite loop
  • a recursive function where the function doesn’t return anything and just prints the values
  • a function where the recursive call is the last thing executed by the function
Q12 | , tot-2)
  • both a() and b() aren’t tail recursive
  • both a() and b() are tail recursive
  • b() is tail recursive but a() isn’t
  • a() is tail recursive but b() isn’t
Q13 | Which of the following statements is false about recursion?
  • every recursive function must have a base case
  • infinite recursion can occur if the base case isn’t properly mentioned
  • a recursive function makes the code easier to understand
  • every recursive function must have a return value
Q14 | Recursion and iteration are the same programming approach.
  • true
  • false
Q15 | What happens if the base condition isn’t defined in recursive programs?
  • program gets into an infinite loop
  • program runs once
  • program runs n number of times where n is the argument given to the function
  • an exception is thrown
Q16 | Which of these is not true about recursion?
  • making the code look clean
  • a complex task can be broken into sub- problems
  • recursive calls take up less memory
  • sequence generation is easier than a nested iteration
Q17 | Which of these is not true about recursion?
  • it’s easier to code some real-world problems using recursion than non-recursive equivalent
  • recursive functions are easy to debug
  • recursive calls take up a lot of memory
  • programs using recursion take longer time than their non-recursive equivalent
Q18 | Which of the following commands will create a list?
  • list1 = list()
  • list1 = []
  • list1 = list([1, 2, 3])
  • all of the mentioned
Q19 | What is the output when we execute list(“hello”)?
  • [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
  • [‘hello’]
  • [‘llo’]
  • [‘olleh’]
Q20 | Suppose list1 is [2445,133,12454,123], what is max(list1)?
  • 2445
  • 133
  • 12454
  • 123
Q21 | Suppose list1 is [3, 5, 25, 1, 3], what is min(list1)?
  • 3
  • 5
  • 25
  • 1
Q22 | Suppose list1 is [1, 5, 9], what is sum(list1)?
  • 1
  • 9
  • 15
  • error
Q23 | To shuffle the list(say list1) what function do we use?
  • list1.shuffle()
  • shuffle(list1)
  • random.shuffle(list1)
  • random.shufflelist(list1)
Q24 | Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation?
  • print(list1[0])
  • print(list1[:2])
  • print(list1[:-2])
  • all of the mentioned
Q25 | Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?
  • error
  • none
  • 25
  • 2