• The AI Problems, The Underlying Assumption, What Is An AI Techniques, The Level Of The Model, Criteria For Success...
  • Defining The Problems As A State Space Search, Production Systems, Production Characteristics, Production System Characteristics...
  • Overview, MiniMax, Alpha-Beta Cut-off, Refinements, Iterative deepening, The Blocks World, Components Of A Planning System....
Showing posts with label PYTHON MCQ. Show all posts
Showing posts with label PYTHON MCQ. Show all posts

Saturday, 1 August 2020

PYTHON GTU MCQ (CH-4 Python List)

CH - 4 Python List


GTU MCQ:-

1.What is the output when we execute list(“hello”)?
a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
b) [‘hello’]
c) [‘llo’]
d) [‘olleh’]

2.Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?
a) 5
b) 4
c) None
d) Error

3.Which of the following commands will create a list?
a) list1 = list()
b) list1 = []
c) list1 = list([1, 2, 3])
d) all of the mentioned

4.Suppose list1 is [2445,133,12454,123], what is max(list1)?
a) 2445
b) 133
c) 12454
d) 123

5.Suppose list1 is [1, 5, 9], what is sum(list1)?
a) 1
b) 9
c) 15
d) Error

6.To shuffle the list(say list1) what function do we use?
a) list1.shuffle()
b) shuffle(list1)
c) random.shuffle(list1)
d) random.shuffleList(list1)

7. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation?
a) print(list1[0])
b) print(list1[:2])
c) print(list1[:-2])
d) all of the mentioned

8.Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
a) [2, 33, 222, 14]
b) Error
c) 25
d) [25, 14, 222, 33, 2]

9.What will be the output of the following Python code?

1. names1 = ['Amir', 'Bear', 'Charlton', 'Daman']
2. names2 = names1
3. names3 = names1[:]
4.  
5. names2[0] = 'Alice'
6. names3[1] = 'Bob'
7.  
8. sum = 0
9. for ls in (names1, names2, names3):
10.                          if ls[0] == 'Alice':
11.                              sum += 1
12.                          if ls[1] == 'Bob':
13.                              sum += 10
14.                       
15.                      print sum

a) 11
b) 12
c) 21
d) 22

10.Suppose list1 is [1, 3, 2], What is list1 * 2?
a) [2, 6, 4]
b) [1, 3, 2, 1, 3]
c) [1, 3, 2, 1, 3, 2]
d) [1, 3, 2, 3, 2, 1]

11.Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:
a) [0, 1, 2, 3]
b) [0, 1, 2, 3, 4]
c) [0.0, 0.5, 1.0, 1.5]
d) [0.0, 0.5, 1.0, 1.5, 2.0]

12.To add a new element to a list we use which command?
a) list1.add(5)
b) list1.append(5)
c) list1.addLast(5)
d) list1.addEnd(5)

13.To insert 5 to the third position in list1, we use which command?
a) list1.insert(3, 5)
b) list1.insert(2, 5)
c) list1.add(3, 5)
d) list1.append(3, 5)

14.To remove string “hello” from list1, we use which command?
a) list1.remove(“hello”)
b) list1.remove(hello)
c) list1.removeAll(“hello”)
d) list1.removeOne(“hello”)

15.Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?
a) 0
b) 4
c) 1
d) 2

16.Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.extend([34, 5])?
a) [3, 4, 5, 20, 5, 25, 1, 3, 34, 5]
b) [1, 3, 3, 4, 5, 5, 20, 25, 34, 5]
c) [25, 20, 5, 5, 4, 3, 3, 1, 34, 5]
d) [1, 3, 4, 5, 20, 5, 25, 3, 34, 5]

17.What will be the output of the following Python code?

1. myList = [1, 2, 3, 4, 5, 6]
2. for i in range(1, 6):
3.     myList[i - 1] = myList[i]
4.  
5. for i in range(0, 6):
6.     print(myList[i], end = " ")

a) 2 3 4 5 6 1
b) 6 1 2 3 4 5
c) 2 3 4 5 6 6
d) 1 1 2 3 4 5

18.What will be the output of the following Python code?

1. names1 = ['Amir', 'Bala', 'Chales']
2.  
3. if 'amir' in names1:
4.     print(1)
5. else:
6.     print(2)

a) None
b) 1
c) 2
d) Error

19.To which of the following the “in” operator can be used to check if an item is in it?
a) Lists
b) Dictionary
c) Set
d) All of the mentioned

20.What will be the output of the following Python code?

1. def increment_items(L, increment):
2.     i = 0
3.     while i < len(L):
4.         L[i] = L[i] + increment
5.         i = i + 1
6.  
7. values = [1, 2, 3]
8. print(increment_items(values, 2))
9. print(values)

a) None         [3, 4, 5]
b) None         [1, 2, 3]
c) [3, 4, 5]      [1, 2, 3]
d) [3, 4, 5]     None

 

 21.What will be the output of the following Python code?

1. values = [[3, 4, 5, 1], [33, 6, 1, 2]]
2.  
3. v = values[0][0]
4. for lst in values:
5.     for element in lst:
6.         if v > element:
7.             v = element
9. print(v)

a) 1
b) 3
c) 5
d) 6

22. What will be the output of the following Python code?

1. values = [[3, 4, 5, 1 ], [33, 6, 1, 2]]
2.  
3. for row in values:
4.     row.sort()
5.     for element in row:
6.         print(element, end = " ")
7.     print()

a) The program prints two rows 3 4 5 1 followed by 33 6 1 2
b) The program prints on row 3 4 5 1 33 6 1 2
c) The program prints two rows 3 4 5 1 followed by 33 6 1 2
d) The program prints two rows 1 3 4 5 followed by 1 2 6 33

23.  What will be the output of the following Python code?

1. def m(list):
2.     v = list[0]
3.     for e in list:
4.       if v < e: v = e
5.     return v
6.  
7. values = [[3, 4, 5, 1], [33, 6, 1, 2]]
8.  
9. for row in values:
10.                          print(m(row), end = " ")

a) 3 33
b) 1 1
c) 5 6
d) 5 33

24. What will be the output of the following Python code?

1. data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
2.  
3. def ttt(m):
4.     v = m[0][0]
5.  
6.     for row in m:
7.         for element in row:
8.            if v < element: v = element:
10.                          return v
12.               print(ttt(data[0]))

a) 1
b) 2
c) 4
d) 5

25. What will be the output of the following Python code?

lst=[3,4,6,1,2]
lst[1:2]=[7,8]
print(lst)

a) [3, 7, 8, 6, 1, 2]
b) Syntax error
c) [3,[7,8],6,1,2]
d) [3,4,6,7,8]

 

Share With Your Geeky Friends...