Lab Assignment 9
1. Write a python program to create a 5-element integer list and display the contents of
the list.
2. Write a python program to create a list of names, roll numbers and percentage of
marks for plus-two and print the list of students based on the descending order of
plus-two marks percentage.
3. Write a python program to create a list of 10 floating point numbers and print all but
last 4 numbers.
4. Write a python program that accepts a list from user. Your program should reverse the
content of list and display it. Do not use reverse () method.
5. Write a python program that accepts a list of 5 students whose names and marks of 3
subjects are read in a comma separated way, now modify the program to remove all
the comma separations from the list.
6. Write a python program to remove the first and last elements from a list.
7. Given the names and grades for each student in a class of students, store them in a
nested list and print the name(s) of any student(s) having the second lowest grade.
Note: If there are multiple students with the second lowest grade, order their names
alphabetically and print each name on a new line.
Example
The ordered list of scores is [20.0, 50.0], so the second lowest score is 50.0. There are
two students with that score: [“beta”, “alpha”]. Ordered alphabetically, the names are
printed as:
alpha
beta
Input Format
The first line contains an integer, N, the number of students.
The 2N subsequent lines describe each student over 2 lines.
- The first line contains a student's name.
- The second line contains their grade.
Constraints
2<=N<=5
There will always be one or more students having the second lowest grade.
Output Format
Print the name(s) of any student(s) having the second lowest grade in. If there are
multiple students, order their names alphabetically and print each one on a new line.
Sample Input 0
5
Harry
37.21
Berry
37.21
Tina
37.2
Akriti
41
Harsh
39
Sample Output 0
Berry
Harry
Explanation 0
There are 5 students in this class whose names and grades are assembled to build the
following list:
python students = [['Harry', 37.21], ['Berry', 37.21], ['Tina', 37.2], ['Akriti', 41],
['Harsh', 39]]
The lowest grade of 37.2 belongs to Tina. The second lowest grade of 37.21 belongs
to both Harry and Berry, so we order their names alphabetically and print each name
on a new line.
8. Consider a list (list = []). You can perform the following commands:
a. insert i e: Insert integer e at position i.
b. print: Print the list.
c. remove e: Delete the first occurrence of integer e .
d. append e: Insert integer e at the end of the list.
e. sort: Sort the list.
f. pop: Pop the last element from the list.
g. reverse: Reverse the list.
Initialize your list and read in the value of n followed by n lines of commands where
each command will be of the 7 types listed above. Iterate through each command in
order and perform the corresponding operation on your list.
Example
N=4
append 1
append 2
insert 3 1
print
append 1: Append 1 to the list, arr = [1].
append 2: Append 2 to the list, arr = [1,2].
insert 3 1: Insert 3 at index 1, arr = [1,3,2].
print: Print the array.
Output:
[1, 3, 2]
Input Format
The first line contains an integer, n, denoting the number of commands.
Each line i of the n subsequent lines contains one of the commands described above.
Constraints
The elements added to the list must be integers.
Output Format
For each command of type print, print the list on a new line.
Sample Input 0
12
insert 0 5
insert 1 10
insert 0 6
print
remove 6
append 9
append 1
sort
print
pop
reverse
print
Sample Output 0
[6, 5, 10]
[1, 5, 9, 10]
[9, 5, 1]