Professional Documents
Culture Documents
Assignment 05
Assignment 05
Assignment 05
Explanation:
1. Firstly, we need to define a list and add the names of the employees inside the list.
2. The second step is to divide our list into two parts. We do this by creating a new list and
adding only the names of the first five employees. To do this, we need to split the list
[:5]. This command prints the elements of the list until the fourth element (from 0 to 4).
To print the second half of the list [5], This command prints the list from the fifth
3. To add a new element to the list, we use append. It will add a new element to the end of
the list. We are adding this name at the end of the second list, following the instructions.
4. To delete an element from the list, we can use the del command, and it will delete the
element that we specify. First, we type del and the name of the list, and then the position
of the element. Here, we are deleting the second element from the first half of the list.
5. To merge two lists, we can use the “+” operator. To do this, we need to create a third list
and add the two existing lists. The third list will contain all the elements of the previous
two lists.
6. For the next step, we need to define another list that will contain the salaries of
employees. Since there are 10 people, we need to add 10 salaries for each employee. To
this, we declare a list and add all the salaries. Moreover, we also need a 4% raise for all
the employees and then calculate their salaries after the raise. 4% raised means 104%,
7. The next step is to sort the list of salaries after the raise. To sort, we use the sort
command, and since we want to display them from biggest to smallest, we reverse them.
8. Finally, to print the top 3 salaries, we need to create a new list, slice the original list, and
only store the three largest salaries. [:3] prints the first three elements since they are
9. To check if our code runs properly, we need to print the output and check if it is what we
wanted it to do.
10. Output (a):
Explanation:
1. First, we need to declare a string. It is called my_sentence, and it contains our sentence.
2. To convert our sentence to a list, we need to use split and also define how Python should
split our string. Here, we tell Python to split the string every time it encounters a space.
3. To reverse our list, we can use the reverse or [::1] command. This command prints all the
Output (b):