0% found this document useful (0 votes)
14 views4 pages

CS 1101-01 Unit 6

Programming Fundamentals Unit 6 Assignment

Uploaded by

sarahhauya1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

CS 1101-01 Unit 6

Programming Fundamentals Unit 6 Assignment

Uploaded by

sarahhauya1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

University of the People

Sarah Hauya

Programming Assignment unit 6

Muhammad Anwa, Instructor

Due by 17th October, 2024


Introduction

To preable, this essay will answer the two parts of the problems given below;

(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 names in a
list here).

1. Split the list into two sub-list namely subList1 and subList2, each containing 5 names.

2. A new employee (assume the name “Kriti Brown”) joins, and you must add that name in subList2.

3. Remove the second employee's name from subList1.

Merge both the lists.

4. Assume there is another list salaryList that stores salary of these employees. Give a rise of 4% to
every employee and update the salaryList.

5. Sort the SalaryList and show top 3 salaries.

6. Write the Python code and output for the same.

Initial list of employees

employeeList = ["Alice", "Bob", "Charlie", "David", "Eve", "Frank", "Grace", "Helen", "Isaac", "Jack"]

# Split the list into two sub-listssubList1 = employeeList[:5]subList2 = employeeList[5:]

Add a new employee

new_employee = "Kriti Brown"

subList2.append(new_employee)

# Remove the second employee's name from subList1subList1.pop(1)

# Merge both the lists merged List = subList1 + subList2

# List of salariessalaryList = [50000, 55000, 60000, 65000, 70000, 75000, 80000, 85000, 90000, 95000]

# Give a 4% raise to every employee and update the salaryList

salaryList = [salary * 1.04 for salary in salaryList]

# Sort the salaryList in descending order

salaryList.sort(reverse=True)
Show the top 3 salaries

top_3_salaries = salaryList[:3]

print("SubList1:", subList1)

print("SubList2:", subList2)

print("Merged List:", mergedList)

print("Updated Salary List:", top_3_salaries)

Finally, the program prints the following information:

SubList1: The first sub-list of employees.

SubList2: The second sub-list of employees.

Merged List: The list that combines both sub-lists.

Updated Salary List: The list of salaries after the 4% raise.

Top 3 Salaries: The top 3 salaries from the updated list.

(b). Design a program such that it converts a sentence into wordlist. Reverse the wordlist then. Write
the code and output for the same.

# Function to convert a sentence into a word list

def sentence_to_wordlist(sentence):

# Split the sentence into words using whitespace as a separator wordlist = sentence.split() return
wordlist

# Function to reverse a word listdef

reverse_wordlist(wordlist): reversed_wordlist = list(reversed(wordlist))

return reversed_wordlist

# Input sentence
input_sentence = " Mosquitoes are small, violent, and mischievous creatures in overalls."

# Convert the sentence into a word list

word_list = sentence_to_wordlist(input_sentence)

Reverse the word list

reversed_word_list = reverse_wordlist(word_list)

# Print the original word list

print("Original Word List:")

print(word_list)

# Print the reversed word listprint("\nReversed Word List:")

Conclusion

To conclude, above are respondes to the two sets of questions given in this assignment in regards to
computer programming.

You might also like