Quiznetik

Problem Solving and Python Programming | Set 3

1. Which module in the python standard library parses options received from the command line?

Correct : A. getopt

2. What is the type of sys.argv?

Correct : B. list

3. f1(). .

Correct : C. 15

4. ,2,3,4 f(5,10,15)

Correct : C. 10 20 30 40

5. (1,2) print(total)

Correct : B. 7

6. Which of the following data structures is returned by the functions globals() and locals()?

Correct : C. dictionary

7. On assigning a value to a variable inside a function, it automatically becomes a global variable.

Correct : B. false

8. What happens if a local variable exists with the same name as the global variable you want to access?

Correct : D. the global variable is shadowed

9. print(a)

Correct : B. 25

10. f() x

Correct : D. 1

11. Which is the most appropriate definition for recursion?

Correct : B. a function execution instance that calls another execution instance of the same function

12. Only problems that are recursively defined can be solved using recursion.

Correct : B. false

13. Which of these is false about recursion?

Correct : C. recursive functions run faster than non- recursive function

14. ,i+j) print(test(4,7))

Correct : D. 17

15. 5 RECURSION

Correct : B. 110

16. What is tail recursion?

Correct : D. a function where the recursive call is the last thing executed by the function

17. , tot-2)

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

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

Correct : D. every recursive function must have a return value

19. Recursion and iteration are the same programming approach.

Correct : B. false

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

Correct : A. program gets into an infinite loop

21. Which of these is not true about recursion?

Correct : C. recursive calls take up less memory

22. Which of these is not true about recursion?

Correct : B. recursive functions are easy to debug

23. Which of the following commands will create a list?

Correct : D. all of the mentioned

24. What is the output when we execute list(“hello”)?

Correct : A. [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]

25. Suppose list1 is [2445,133,12454,123], what is max(list1)?

Correct : C. 12454

26. Suppose list1 is [3, 5, 25, 1, 3], what is min(list1)?

Correct : D. 1

27. Suppose list1 is [1, 5, 9], what is sum(list1)?

Correct : C. 15

28. To shuffle the list(say list1) what function do we use?

Correct : C. random.shuffle(list1)

29. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation?

Correct : D. all of the mentioned

30. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?

Correct : C. 25

31. Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?

Correct : A. [2, 33, 222, 14]

32. >>>print(names[-1][-1])

Correct : D. n

33. print sum

Correct : B. 12

34. Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:

Correct : C. [0.0, 0.5, 1.0, 1.5]

35. >>>list1 < list2 is

Correct : B. false

36. To add a new element to a list we use which command?

Correct : B. list1.append(5)

37. To insert 5 to the third position in list1, we use which command?

Correct : B. list1.insert(2, 5)

38. To remove string “hello” from list1, we use which command?

Correct : A. list1.remove(“hello”)

39. Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)?

Correct : D. 2

40. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?

Correct : D. 2

41. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.reverse()?

Correct : D. [3, 1, 25, 5, 20, 5, 4, 3]

42. >>>"Welcome to Python".split()

Correct : A. [“welcome”, “to”, “python”]

43. >>>list("a#b#c#d".split('#'))

Correct : A. [‘a’, ‘b’, ‘c’, ‘d’]

44. >>>print(indexOfMax)

Correct : A. 1

45. print(myList[i], end = " ")

Correct : C. 2 3 4 5 6 6

46. >>>print(list2)

Correct : B. [4, 3]

47. print(v)

Correct : C. [44, 2, 3]

48. print(v)

Correct : C. [1, 2, 3]

49. print(2)

Correct : C. 2

50. print(names2[2][0])

Correct : D. c

51. numbers = [1, 2, 3, 4] numbers.append([5,6,7,8]) print(len(numbers))

Correct : B. 5

52. To which of the following the “in” operator can be used to check if an item is in it?

Correct : D. all of the mentioned

53. print(len(list1 + list2))

Correct : D. 8

54. print(len(mylist))

Correct : C. 5

55. return result

Correct : A. return a list containing every third item from l starting at index 0

56. print(veggies)

Correct : A. [‘carrot’, ‘celery’, ‘broccoli’, ‘potato’, ‘asparagus’] correct 1.00

57. >>>m = [[x, x + 1, x + 2] for x in range(0, 3)]

Correct : B. [[0, 1, 2], [1, 2, 3], [2, 3, 4]]

58. m = [[x, y] for x in range(0, 4) fo r y in range(0, 4)]

Correct : C. 16

59. print(v)

Correct : D. 33

60. print(v)

Correct : A. 1

61. print(matrix[i][1], end = " ")

Correct : D. 2 5 9 13

62. print(m(row), end = " ")

Correct : D. 5 33

63. print(data[1][0][0])

Correct : D. 5

64. print(ttt(data[0]))

Correct : C. 4

65. print(points)

Correct : C. [[0.5, 0.5], [1, 2], [3, 1.5]]

66. ,b)) print(a)

Correct : C. [3,5]

67. for i in range(3)]; print(x);

Correct : A. [0, 1, 2]

68. ==0: i; else: i+1; for i in range(4)])

Correct : C. error

69. Which of the following is the same as list(map(lambda x: x**-1, [1, 2, 3]))?

Correct : C. [1/x for x in (1, 2, 3)]

70. for x in l]

Correct : B. [1, 0, 1, 0, 1]

71. for y in l2]

Correct : C. [4, 5, 6, 8, 10, 12, 12, 15, 18]

72. Write the list comprehension to pick out only negative integers from a given list ‘l’.

Correct : D. [x for x in l if x<0]

73. =[x+y for x, y in zip(l1, l2)] l3

Correct : D. [0, 0, 0]

74. Write a list comprehension for number and its cube for l=[1, 2, 3, 4, 5, 6, 7, 8, 9].

Correct : A. [x**3 for x in l]

75. )*5/9) for x in t]

Correct : D. error

76. Write a list comprehension for producing a list of numbers between 1 and 1000 that are divisible by 3.

Correct : B. [x for x in range(1000) if x%3==0]

77. Write a list comprehension to produce the list: [1, 2, 4, 8, 16……212].

Correct : A. [(2**x) for x in range(0, 13)]

78. , x is even} (including zero)

Correct : D. [x for x in range(0, 20) if (x%2==0)]

79. , i)]

Correct : C. a list of non prime numbers, up to 50

80. ] for row in (0, 1, 2)]

Correct : C. [2, 5, 8]

81. for col in row] for row in A]

Correct : A. [[11, 12, 13], [14, 15, 16], [17, 18, 19]]

82. -i] for i in range(len(A))]

Correct : C. [3, 5, 7]

83. ) for col in range(3)]

Correct : A. [3, 6, 9, 16, 20, 24, 35, 40, 45]

84. , row2)] for (row1, row2) in zip(A, B)]

Correct : B. [[3, 6, 9], [16, 20, 24], [35, 40, 45]]

85. >>>t[1:3]

Correct : C. (2, 4)

86. >>>t[1:-1]

Correct : C. (2, 4)

87. >>>[t[i] for i in range(0, len(t), 2)]

Correct : C. [1, 4, 8]

88. d["john"]

Correct : A. 40

89. >>>t1 < t2

Correct : B. false

90. >>>print len(my_tuple)

Correct : D. error

91. What is the data type of (1)?

Correct : B. integer

92. What type of data is: a=[(1,1),(2,4),(3,9)]?

Correct : B. list of tuples

93. Is the following Python code valid? >>> a,b=1,2,3

Correct : C. no, too many values to unpack

94. Tuples can’t be made keys of a dictionary.

Correct : B. false

95. Which of the following statements create a dictionary?

Correct : D. all of the mentioned

96. d = {"john":40, "peter":45}

Correct : B. “john” and “peter”

97. "john" in d

Correct : A. true

98. d1 == d2

Correct : B. false

99. d1 > d2

Correct : C. error

100. Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?

Correct : C. del d[“john”]