Wednesday, February 2, 2022

LIST- Exercise [QUESTIONS]

LIST - Exercise

Theory Question:

  1. The record of a student (Name, Roll No., Marks in five subjects and percentage of marks) is stored in the following list:
    stRecord = ['Raman','A-36',[56,98,99,72,69],78.8]
    Write Python statements to retrieve the following information from the list stRecord.
    a) Percentage of the student
    b) Marks in the fifth subject
    c) Maximum marks of the student
    d) Roll no. of the student
    e) Change the name of the student from ‘Raman’ to ‘Raghav’
  1. What is the data type for the object L below in python?
    L=[1,4,’thanks’,34]
    (a) list (b) dictionary (c) tuple (d) array
  1. Given the lists L=[10,30,16,8,50,17,12,42] , write the output of
    print(L[2:5])
  1. Write the output of the following code
    L=[‘cs’,’maths’,’phy’,’chem’,’eng’]
    print(len(L))
  1. Write the names of the immutable data objects from the following :
    A. List
    B. Tuple
    C. String
    D. Dictionary
  1. A List is declared as
    L = ['ONE', 'TWO', 'THREE']
    What will be the output of the statement ?
    print(max(L))

Programming Problems:

  1. Write a program to find the number of times an element occurs in the list.

  2. Write a program to read a list of n integers (positive as well as negative). Create two new lists, one having all positive numbers and the other having all negative numbers from the given list. Print all three lists.
  3. Write a program to read a list of n integers and find their median. Note: The median value of a list of values is the middle one when they are arranged in order. If there are two middle values then take their average.

  4. Write a program to read a list of elements. Modify this list so that it does not contain any duplicate elements, i.e., all elements occurring multiple times in the list should appear only once.

  5. Write a program to read a list of elements. Input an element from the user that has to be inserted in the list. Also input the position at which it is to be inserted. Write a user defined function to insert the element at the desired position in the list.

  6. Write a program to read elements of a list.
    1. The program should ask for the position of the element to be deleted from the list. Write a function to delete the element at the desired position in the list.
    2. The program should ask for the value of the element to be deleted from the list. Write a function to delete the element of this value from the list.

  7. Write a program to find the largest and smallest numbers in a list.

  8. Write a program to find the third largest number in a list.

  9. Write a menu driven program to perform various list operations, such as:
    • Append an element
    • Insert an element
    • Append a list to the given list
    • Modify an existing element
    • Delete an existing element from its position
    • Delete an existing element with a given value
    • Sort the list in ascending order
    • Sort the list in descending order
    • Display the list.

Share: