| Snaprecruit.com

| Snaprecruit.com

Interview question based on skill :

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. Which of the following will never be displayed on executing print(random.choice({0: 1, 2: 3}))?

Correct Answer is : 0

2. What does random.shuffle(x) do when x = [1, 2, 3]?

Correct Answer is : shuffle the elements of the list in-place

3. Which type of elements are accepted by random.shuffle()?

Correct Answer is : lists

4. What is the range of values that random.random() can return?

Correct Answer is : [0.0, 1.0)

5. Which is the most appropriate definition for recursion?

Correct Answer is : A function execution instance that calls another execution instance of the same function

6. Only problems that are recursively defined can be solved using recursion. True or False?

Correct Answer is : FALSE

7. Which of these is false about recursion?

Correct Answer is : Recursive functions run faster than non-recursive function

8. Fill in the line of code for calculating the factorial of a number. def fact(num): if num == 0: return 1 else: return _____________________

Correct Answer is : num*fact(num-1)

9. What is the output of the following piece of code? def test(i,j): if(i==0): return j else: return test(i-1,i+j) print(test(4,7))

Correct Answer is : 13

10. What is the output of the following code? l=[] def convert(b): if(b==0): return l dig=b%2 l.append(dig) convert(b//2) convert(6) l.reverse() for i in l: print(i,end="")

Correct Answer is : 110

11. What is tail recursion?

Correct Answer is : A function where the recursive call is the last thing executed by the function

12. Observe the following piece of code? def a(n): if n == 0: return 0 else: return n*a(n - 1) def b(n, tot): if n == 0: return tot else: return b(n-2, tot-2)

Correct Answer is : b() is tail recursive but a() isn’t

13. Which of the following statements is false about recursion?

Correct Answer is : Every recursive function must have a return value

14. What is the output of the following piece of code? def fun(n): if (n > 100): return n - 5 return fun(fun(n+11));   print(fun(45))

Correct Answer is : 100

15. Recursion and iteration are the same programming approach. True or False?

Correct Answer is : FALSE

16. What happens if the base condition isn’t defined in recursive programs?

Correct Answer is : Program gets into an infinite loop

17. Which of these is not true about recursion?

Correct Answer is : Recursive calls take up less memory

18. Which of these is not true about recursion?

Correct Answer is : Recursive functions are easy to debug

19. What is the output of the following piece of code? def a(n): if n == 0: return 0 elif n == 1: return 1 else: return a(n-1)+a(n-2) for i in range(0,4): print(a(i),end=" ")

Correct Answer is : 0 1 1 2

20. Which module in Python supports regular expressions?

Correct Answer is : re