Showing posts with label List. Show all posts
Showing posts with label List. Show all posts

Computer Science - Informatics Practices Class XI/XII Python List Solved Test Part 10

 

Computer Science - Informatics Practices Class XI/XII Python List Solved Test  Part 10

Q1. Write a program to input a number and count the occurrence of that number in the given list.

       B = [34,21,3,12,34,56,76,5,4,21,12,34]

Q2. Write a program to separate the character and numeric value from a given list and store them in a separate list.

    A = [1,’f’,2,’b’,3,4,’h’,j’,6,9,0,’k’]

Q3. What do you mean by sorting?

Q4. Name any two sorting techniques.

Q5. Write a program to create a list of 10 integers and sort the list in increasing order using bubble sort.

Q6. Suppose total element in a list are 7, so how many times the outer loop will be executed in bubble sort.

Q7. A = [23,45,21,78,43]

Write the order of the elements in the above list after first pass of bubble sort (in ascending order).

Q8. Write any one application of bubble sort.

Computer Science - Informatics Practices Class XI/XII Python List Solved Test Part 9

 

Computer Science - Informatics Practices Class XI/XII Python List Solved Test  Part 9

Q1. Write a program to check whether a number (accepted from user) is present in a list.

Q2. Name a function which is used to find the largest number from a list.

Q3. ______ function returns the smallest value from the list.

Q4. max() function works in a list which have all values of same data type. (T/F)

Q5. Write the full form of ASCII value.

Q6. ASCII value of ‘A’ is ______.

Q7. ASCII value of ‘b’ is ______.

Q8. Write the output of the following:

a = [11,42,31,14]

print(max(a))

print(min(a))

print(a.index(42))

 

 Q9. Write the output of the following:

a = [11,42,31,'a',14]

print(max(a))

 

Q10. Write the output of the following:

a = ['amit','Amit','Amita']

print(max(a))

print(min(a))

 

 

 

Computer Science - Informatics Practices Class XI/XII Python List Solved Test Part 8

 

Computer Science - Informatics Practices Class XI/XII Python List Solved Test  Part 8

Q1. Explain the following functions in reference to list with example

a.     count()

b.     clear()

c.     pop()

d.     remove()

Q2. What is the difference between del statement and pop() function.

Q3. Write the output of the following:

       

Q4. Out of del and pop() which one return the deleted element.

Q5. remove() function take _______ (element/index) as argument.

Q6. Name a function/statement which can delete more than one element from the list.

Q7. Name a function which can delete only one element from the list.

Q8. Write a program to delete/remove all the negative elements from the list.

Q9. Write a program to delete/remove all the odd numbers from the list.

Q10. Write a program to delete/remove all the numbers less than 10 from the list.

Computer Science - Informatics Practices Class XI/XII Python List Solved Test Part 7

 

Computer Science - Informatics Practices Class XI/XII Python List Solved Test  Part 7

Q1. Write the role of reverse() function in list.

Q2. reverse() function create new list. (T/F)

Q3. >>> a = [1,2,3,4]

    >>> a.reverse()

    >>> print(a)

Write the output of above code.

Q4. What type of error return by index() function,

    if element is not present in list?

Q5. a = [1,5,7,5]

    b = a.index(5)

    print(b)

Write the output of above code.

Q6. Write the output of the following:

Code

Output

 

 

 

 

Q7. len() function returns the ______ of the list.

Q8. By default sort() function arrange the 

    elements in ________ order  

    (increasing/decreasing)

Q9. Write code to arrange elements of following 

    list in increasing order.

    A = [23,12,45,32,67,33]

Q10. What do you mean by nested list. Give one

     example of nested list.


  

SOLUTIONS

Q1. Write the role of reverse() function in list.

Ans reverse() function arrange the elements of 

    list in the reverse order.

Q2. reverse() function create new list. (T/F)

Ans. False

Q3. >>> a = [1,2,3,4]

    >>> a.reverse()

    >>> print(a)

Write the output of above code.

Ans. [4,3,2,1]

Q4. What type of error return by index() function,

    if element is not present in list?

Ans. Index error

Q5. a = [1,5,7,5]

    b = a.index(5)

    print(b)

Write the output of above code.

Ans. 1

Q6. Write the output of the following:

Code

Output

 Indexerror

 [1,'a',3,4]

 [4,5,6,7]

 

Q7. len() function returns the ______ of the list.

Ans length

Q8. By default sort() function arrange the 

    elements in ________ order  

    (increasing/decreasing)

Ans. increasing

Q9. Write code to arrange elements of following 

    list in increasing order.

    A = [23,12,45,32,67,33]

Ans. A.sort()

Q10. What do you mean by nested list. Give one

     example of nested list.

Ans. A list inside another list is called nested list. for example

A = [1,2,3,['a','b']]

 

 

 

 

Computer Science - Informatics Practices Class XI/XII Python List Solved Test Part 6

 

Computer Science - Informatics Practices Class XI/XII Python List Solved Test  Part 6

Q1. Write a program to create list of the

    following (take input from the user)

a.     Any five students name

b.     Any five numbers

c.     Any five alphabets

d.     Any five name of colors.

Q2. Write a program to accept 10 numbers from the user, if the number is odd, and then add that number to the list.

(input numbers are : 1,2,3,4,5,6,7,8,9,10

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

Q3. Write a program to find the largest number from the following list.(without using inbuilt function)

A = [23, 12, 45, 67, 55]

Q4. Write a program to find the second largest number from the following list.

A = [23, 12, 45, 67, 55]

Q5. Explain the extend() function with example.

Q6. Write any one difference between insert() and append() function.


SOLUTIONS

Q1. Write a program to create list of the

    following (take input from the user)

a.     Any five students name

b.     Any five numbers

c.     Any five alphabets

d.     Any five name of colors.


Ans a)

a = []
for i in range(5):
nm=input("Enter student name")
a.append(nm)
print(a)

b)
a = []
for i in range(5):
num=int(input("Enter any number"))
a.append(num)
print(a)

c)
a = []
for i in range(5):
al=input("Enter any alphabet")
a.append(al)
print(a)

d)

a = []
for i in range(5):
cl=input("Enter name of any color")
a.append(cl)
print(a)

Q2. Write a program to accept 10 numbers from the user, if the number is odd, and then add that number to the list.

(input numbers are : 1,2,3,4,5,6,7,8,9,10

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

Ans.

a = []
for i in range(10):
num=int(input("Enter any number"))
if(num%2!=0):
a.append(num)
print(a)

Q3. Write a program to find the largest number from the following list.(without using inbuilt function)

A = [23, 12, 45, 67, 55]

Ans

A = [23, 12, 45, 67, 55]
max=A[0]
for i in range(len(A)):
if A[i]>max:
max=A[i]
print(max)

Q4. Write a program to find the second largest number from the following list.

A = [23, 12, 45, 67, 55]

Ans.

A = [23, 12, 45, 67, 55]
A.sort()
print(A[-2])

Q5. Explain the extend() function with example.

Ans. extend() function add complete list or specified elements of list at the end of another list. for example

A = [23, 12, 45, 67, 55]
B = ["Amit",2,3]
A.extend(B)
print(A)

OUTPUT : [23, 12, 45, 67, 55, 'Amit', 2, 3]

Q6. Write any one difference between insert() and append() function.

Ans. insert() function add elements at the specified index of list while append() function add the elements at the end of the list.

Most Recently Published

File Handling Test 6

 File Handling Test 6 Q1 . Do we need to use the close() function when we use 'with' statement to open a file? Q2. Which mode you wi...

CS - IP Assignment/Worksheet