Programming Assignment Unit 6
Programming Assignment Unit 6
Ayesha Gul
Dr Josiah Jolaoluwa
By the end of this assignment, you will be able to perform addition, deletion, and sorting on the
elements of the list as well shall be able to experiment list and related operators
(a). Consider that you are working as Data Analyst in an organization. The HR department needs
you to carry out following operation on existing list of 10 employees name (you can assume 10
Split the list into two sub-list namely subList1 and subList2, each containing 5 names.
A new employee (assume the name “Kriti Brown”) joins, and you must add that name in
subList2.
Assume there is another list salaryList that stores salary of these employees. Give a rise of 4% to
(b). Design a program such that it converts a sentence into wordlist. Reverse the wordlist then.
Answer:
Lists are one of the most fundamental data structures in Python, allowing efficient
storage, manipulation, and organization of data. This assignment explores various list operations,
including addition, deletion, sorting, and merging, within a practical HR scenario. In the first
part, we work with a list of employee names, perform operations like splitting, adding, removing,
and updating salary records with a percentage increase. The second part demonstrates string
3
Programming Assignment Unit 6
manipulation by converting a sentence into a word list and reversing it. These exercises provide
hands-on experience with list-related functions, enhancing data management skills crucial for
real-world applications.
Part 1:
Input:
Explanation:
The input for this part consists of a list of 10 employee names based on Stranger Things
characters. The names are initially stored in the employees list. The list is then split into two
sub-lists: subList1 contains the first five names, and subList2 contains the remaining five. A new
employee, "Kriti Brown," is added to subList2, and the second employee in subList1 is removed.
The modified sub-lists are then merged to form a final list, mergedList. Additionally, a salaryList
4
Programming Assignment Unit 6
is provided, where each salary is increased by 4%, and the updated salaries are stored in
updatedSalaryList. The list is sorted in descending order, and the top three salaries are extracted
and displayed.
Output:
Explanation:
The output displays the modified sub-lists after addition and deletion operations. It then presents
the final merged employee list. The updated salary list, which includes a 4% raise for each
employee, is shown next. Finally, the top three highest salaries from the sorted salary list are
displayed. These results demonstrate list operations such as slicing, appending, deletion,
Part 2:
Input:
5
Programming Assignment Unit 6
Explanation:
The input for this part consists of a sentence, "Stranger Things is an amazing series", which is
stored in the sentence variable. The program converts this sentence into a list of words using the
.split() function. The resulting word_list contains each word as a separate element in a list.
Output:
Explanation:
The program first prints the word_list, showing the sentence split into individual words. Then, it
6
Programming Assignment Unit 6
reverses the list using the reversed() function and stores the result in reversed_word_list. Finally,
the reversed word list is printed, displaying the sentence with words in reverse order. This part of
the assignment highlights string manipulation techniques, particularly list conversion and
reversal.
7
Reference List
https://docs.python.org/3/using/windows.html
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree Press.
https://greenteapress.com/thinkpython2/thinkpython2.pdf