You are on page 1of 1

Programming assignment Unit6 (Part 1-2)

Part 1
Part 1 (Explaining The Code)
The code begins by defining a list of employees' names called employees .

It then splits the employees list into two sublists, subList1 and subList2 , using list slicing. subList1 contains
the first five names in the original list, and subList2 contains the remaining names.
The code adds a new employee, "Kriti Brown", to subList2 using the append() method.
Next, the code removes the second employee's name from subList1 using the del statement.
The code then merges both sublists into a single list called mergedList by concatenating subList1 and
subList2 .
A list of salaries for each employee, called salaryList , is initialized.
The code applies a 4% raise to each employee's salary by iterating through salaryList using a for loop and
multiplying each element by 1.04.
The code then sorts salaryList in descending order using the sorted() function and the reverse=True parameter.
The sorted list is stored in the variable sortedSalaries .
Finally, the code extracts the top 3 salaries from sortedSalaries by using list slicing and stores them in the
variable top3Salaries .
The code concludes by printing the sublists, merged list, updated salary list, and the top 3 salaries to the
console.
The output

The output provides the updated employee list, sub-lists, the added and removed employees, the merged list,
and the top 3 salaries. This code demonstrates how to manipulate lists and perform calculations with for loops,
making it suitable for HR or data analysts working with employee data.

Part2

We start with an input sentence.

We split the sentence into a word list using the split() method, which divides the sentence based on whitespace.

The word list is then reversed using slicing ([::-1]).

The reversed word list is joined back into a sentence using the join() method.

The program displays the original sentence, the word list, and the reversed sentence.

This program effectively converts the sentence into a list of words and reverses their order, which is a common
text manipulation task.

You might also like