0% found this document useful (0 votes)
3 views3 pages

SET 1 Exercise

The document outlines an individual assignment for 2025, consisting of exercises focused on Python programming with lists, tuples, sets, strings, and dictionaries. Each exercise includes specific tasks such as creating, modifying, and manipulating data structures in Python. The assignment aims to enhance practical coding skills through various programming challenges.

Uploaded by

tugumekeith022
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)
3 views3 pages

SET 1 Exercise

The document outlines an individual assignment for 2025, consisting of exercises focused on Python programming with lists, tuples, sets, strings, and dictionaries. Each exercise includes specific tasks such as creating, modifying, and manipulating data structures in Python. The assignment aims to enhance practical coding skills through various programming challenges.

Uploaded by

tugumekeith022
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/ 3

Individual ASSIGNMENT ONE 2025

Exercise1 (Lists)

1. Create a list with 5 items (names of people) and write a python program to output the
2nd item.
2. Write a python program to change the value of the first item to a new value
3. Write a python program to add a sixth item to the list
4. Write a python program to add “Bathel” as the 3rd item in your list
5. Write a python program to remove the 4th item from the list
6. Use negative indexing to print the last item in your list
7. Create a new list with 7 items and use a range of indexes to print the 3 rd, 4th and 5th
items.
8. Write a list of countries and make a copy of it.
9. Write a python program to loop through the list of countries
10. Write a list of animal names and sort them in both descending and ascending order.
11. Using the list above, write a python program to output only animal names with the
letter ‘a’ in them
12. Write two lists, one containing your first names and the other your second names. Join
the two lists.

Exercise2 (Tuples)

1. Consider the tuple below;


x = (“samsung”, “iphone”, “tecno”, “redmi”)
Write a python program to output your favorite phone brand.

2. Use negative indexing to print the 2nd last item in your tuple.
3. Using the phones list above, write a python program to update “iphone” to “itel”
4. Write a python program to add “Huawei” to your tuple.
5. Write a python program to loop through the tuple above.
6. Write a python program to remove/delete the first item in your tuple.
7. Using the tuple() constructor, create a tuple of the cities in Uganda.
8. Write a python program to unpack your tuple.
9. Use a range of indexes to print the 2nd, 3rd and 4th cities in your tuple above.
10. Write two tuples, one containing your first names and the other your second names.
Join the two tuples.
11. Create a tuple of colors and multiply it by 3.
12. Return the number of times 8 appears in this tuple
thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)

Exercise3 (Sets)

1. Use the set() constructor to create a set of 3 of your favorite beverages.


2. Use the correct method to add 2 more items to the beverages set.
3. Given the set below;
mySet = {“oven”, “kettle”, “microwave”, “refrigerator”}
Check if microwave is present in the set.
4. Write a python program to remove “kettle” from the set above.
5. Write a python program to loop through the set above.
6. Write a set of 4 items and a list of two items. Write a python program to add elements
in the list to elements in the set.
7. Write two sets, one containing your ages and the other your first names. Join the two
sets.

Exercise4 (Strings)

1. Declare two variables, an integer and a string and use the correct method to
concatenate the two variables.
2. Consider the example below;
txt = “ Hello, Uganda! ”
Output the string without spaces at the beginning, in the middle and at the end.
3. Write a python program to convert the value of ‘txt’ to uppercase.
4. Write a python program to replace character ‘U’ with ‘V’ in the string above.
5. Using the code below, write a python program to return a range of characters in the 2 nd,
3rd and 4th position.
y = “I am proudly Ugandan”
6. The piece of code below will give an error when output;
x = “All “Data Scientists” are cool!”
Write a python program to correct it.

Exercise5 (Dictionaries)

1. With reference to the dictionary below, write a python program to print the value of the
shoe size.
Add this dictionary to your .py file
Shoes = {
“brand” : “Nick”,
“color” : “black”,
“size” : 40
}
2. Write a python program to change the value “Nick” to “Adidas”
3. Write a python program to add a key/value pair "type”: "sneakers" to the dictionary
4. Write a python program to return a list of all the keys in the dictionary above.
5. Write a python program to return a list of all the values in the dictionary above.
6. Check if the key “size” exists in the dictionary above.
7. Write a python program to loop through the dictionary above.
8. Write a python program to remove “color” from the dictionary.
9. Write a python program to empty the dictionary above.
10. Write a dictionary of your choice and make a copy of it.
11. Write a python program to show nested dictionaries

You might also like