Skip to main content

COMPUTER SCIENCE: ASSIGNMENT – LIST

 

COMPUTER SCIENCE: ASSIGNMENT – LIST

CLASS XI

 

Q1. MCQ

1. What is the output of the following list function?

sampleList = [10, 20, 30, 40, 50]

sampleList.pop()

print(sampleList)

sampleList.pop(2)

print(sampleList)

a. [20, 30, 40, 50]

[10, 20, 40]

b. [10, 20, 30, 40]

[10, 20, 30, 50]

c. [10, 20, 30, 40]

[10, 20, 40]


2. What is the output of the following code

list1 = ['xyz', 'zara', 'PYnative']

print (max(list1))

a. PYnative

b. zara


3. What is the output of the following code

my_list = ["Hello", "Python"]

print("-".join(my_list))

a. HelloPython-

b. Hello-Python

c. -HelloPython


4. In Python, list is mutable

a. False

b. True


5. What is the output of the following list assignment

aList = [4, 8, 12, 16]

aList[1:4] = [20, 24, 28]

print(aList)

a. [4, 20, 24, 28, 8, 12, 16]

b. [4, 20, 24, 28]


6. Select all the correct options to join two lists in Python

listOne = ['a', 'b', 'c', 'd']

listTwo = ['e', 'f', 'g']

a. newList = listOne + listTwo

b. newList = extend(listOne, listTwo)

c. newList = listOne.extend(listTwo)

d. newList.extend(listOne, listTwo) 

 

7. What is the output of the following list operation

aList = [10, 20, 30, 40, 50, 60, 70, 80]

print(aList[2:5])

print(aList[:4])

print(aList[3:])

a. [20, 30, 40, 50]

[10, 20, 30, 40]

[30, 40, 50, 60, 70, 80]

b. [30, 40, 50]

[10, 20, 30, 40]

[40, 50, 60, 70, 80]


8. What is the output of the following list function?

sampleList = [10, 20, 30, 40, 50]

sampleList.append(60)

print(sampleList)

sampleList.append(60)

print(sampleList)

a. [10, 20, 30, 40, 50, 60]

b. [10, 20, 30, 40, 50, 60]

c. [10, 20, 30, 40, 50, 60]

d. [10, 20, 30, 40, 50, 60, 60]


9. What is the output of the following code

aList = ["PYnative", [4, 8, 12, 16]]

print(aList[0][1])

print(aList[1][3])

a. P 8

Y 16

b. P

12

c. Y

16


10. What is the output of the following

aList = [5, 10, 15, 25]

print(aList[::-2])

a. [15, 10, 5]

b. [10, 5]

c. [25, 10]


11. What will be the output?

values = [[3, 4, 5, 1], [33, 6, 1, 2]]

v = values[0][0]

for lst in values:

for element in lst:

if v > element:

v = element

print(v)

a. 1

b. 3

c. 5 

d. 6


12. What command is used to insert 6 in a list ‘‘L’’ at 3rd position ?

a. L.insert(2,6)

b. L.insert(3,6)

c. L.add(3,6)

d. L.append(2,6)


Q2.1 What will be the output of the following code snippet?

arr = [1, 2, 3, 4, 5, 6]

for i in range(1, 6):

arr[i - 1] = arr[i]

for i in range(0, 6):

print(arr[i], end = " ")

2. What will be the output of the following code snippet?

fruit_list1 = ['Apple', 'Berry', 'Cherry', 'Papaya']

fruit_list2 = fruit_list1

fruit_list3 = fruit_list1[:]

fruit_list2[0] = 'Guava'

fruit_list3[1] = 'Kiwi'

sum = 0

for ls in (fruit_list1, fruit_list2, fruit_list3):

if ls[0] == 'Guava':

sum += 1

if ls[1] == 'Kiwi':

sum += 20 

print (sum)


3. What will be the output of the following code snippet?

L = [2e-04, 'a', False, 87]

T = (6.22, 'boy', True, 554)

for i in range(len(L)):

if L[i]:

L[i] = L[i] + T[i]

else:

T[i] = L[i] + T[i]

break


4. What will be the output of the following code snippet?

L1 = [1, 1.33, 'GFG', 0, 'NO', None, 'G', True]

val1, val2 = 0, ''

for x in L1:

if(type(x) == int or type(x) == float):

val1 += x

elif(type(x) == str):

val2 += x

else:

break

print(val1, val2)


5. What will be the output of the following code snippet?

L = [1, 3, 5, 7, 9]

print(L.pop(-3), end = ' ')

print(L.remove(L[0]), end = ' ')

print(L) 


Q3. Program list

1. Write a Python program to sum all the items in a list.

2. Write a Python program to multiplies all the items in a list.

3. Write a Python program to get the largest number from a list.

4. Write a Python program to get the smallest number from a list.

5. Write a Python program to count the number of strings where the string length is 2 or more and the first and last character are same from a given list of strings.

Sample List : ['abc', 'xyz', 'aba', '1221']

Expected Result : 2

6. Write a Python program to remove duplicates from a list.

7. Write a Python program to find the list of words that are longer than n from a given list of words.

8. Write a Python program to print a specified list after removing the 0th, 4th and 5th elements.

Sample List : ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow']

Exp

ected Output : ['Green', 'White', 'Black']

9. Write a Python program to print the numbers of a specified list after removing even numbers from it.

10. Write a Python program to generate and print a list of first and last 5 elements where the values are square of numbers between 1 and 30 (both included).

11. Write a Python program to get the difference between the two lists.

12. Write a Python program to convert a list of characters into a string.

13. Write a Python program to find the index of an item in a specified list.

14. Write a Python program to append a list to the second list.

15. Write a Python program to find the second smallest number in a list.

16. Write a Python program to check whether a list contains a sublist.


Comments

Popular posts from this blog

GRADE XII - Python Connectivity with MySQL

  Python Connectivity with MySQL In real-life applications, the data inputted by the user and processed by the application needs to be saved permanently, so that it can be used for future manipulation. Usually, input and output data is displayed during execution but not stored, as it resides in main memory , which is temporary — i.e., it gets erased once the application is closed. This limitation can be overcome by sending the data to be stored in a database , which is made accessible to the user through a Front-End interface . Key Concepts Database A database is an organized collection of data that is stored and accessed electronically from a computer system. DBMS (Database Management System) A DBMS is software that interacts with end-users, applications, and the database to capture and analyze data. Front-End The Front-End is the user interface of the application, responsible for input/output interaction with the user. Back-End The Back-End refe...

GRADE XI | DESIGN THINKING & INNOVATION (848) | INTRO | CH-1

  DESIGN THINKING &  INNOVATION (848)  INTRODUCTION LINK : INTRODUCTION PPT PPT LINK Notes: Design Thinking and Innovation Grade XI Introduction Section   I. What is Design? (0.1.1) Definitions from Experts: John Maeda: "Design is solution to a problem". Saul Bass: "Design is thinking made visual". Charles Eames:   “Design is a plan for arranging elements in such a way as best to accomplish a particular purpose.” Steve Jobs:  "Design is not just what it looks like and feels like. Design is how it works". Prof. Sudhakar Nadkarni:  "Essentials of design are— purity, precision, details". Design is a way of understanding needs, identifying problems, and creating appropriate and innovative solutions. It is not only about appearance, but also about usefulness and sustainability. Design is explained as something that helps solve problems and make a positive difference. Key ...