Goal: Practice creating, indexing, slicing, and looping over lists.
Instructions:
- Create a list of 5 products:
"Keyboard","Mouse","Monitor","Speaker","Webcam". - Print the first and last product.
- Add
"Headphones"to the list. - Remove
"Speaker". - Loop through the list and print each product in uppercase.
- Print the total number of products in the list.
- Slice the list to get the first 3 products and print them.
- Sort the list alphabetically and print it.
Goal: Practice creating and using dictionaries.
Instructions:
- Create a dictionary for a product:
product = {"name": "Keyboard", "units_sold": 5, "unit_price": 20.0}- Print the product name and total revenue (
units_sold * unit_price). - Add a new key
"region"with value"North". - Update
"units_sold"to 10. - Loop through the dictionary and print each key and value.
- Create a list of 3 such product dictionaries with different values.
- Calculate and print the total revenue for all products in the list.
Goal: Practice string manipulation.
Instructions:
- Take the string
"Python Programming". - Print it in lowercase and uppercase.
- Count how many times
"o"appears. - Replace
"Python"with"Java". - Split the string into a list of words.
- Join the list back into a single string with a hyphen (
-) between words.
Goal: Practice if/else statements.
Instructions:
- Ask the user for a number.
- Print
"Even"if the number is even,"Odd"if it’s odd. - Print
"Large"if the number > 100,"Small"otherwise.
Goal: Practice for and while loops.
Instructions:
- Create a list of numbers
[2, 4, 6, 8, 10]. - Print each number multiplied by 2 using a
forloop. - Using a
whileloop, print numbers from 1 to 5.
Goal: Practice reading and writing files.
Instructions:
- Create a text file
products.txtwith the following content:
Keyboard
Mouse
Monitor
Speaker
Webcam
-
Write a Python program to:
- Read the file and print each line.
- Count the number of products.
- Add
"Headphones"to the file.
Goal: Apply all concepts in a small “Store Sales Analysis” project.
Instructions:
- Create a CSV file
sales.csv:
date,product,region,units_sold,unit_price
2025-10-01,Keyboard,North,5,20.0
2025-10-01,Mouse,South,10,15.0
2025-10-02,Keyboard,South,3,21.0
2025-10-02,Monitor,North,2,150.0
2025-10-03,Mouse,North,8,14.5
-
Read the CSV file and store data as list of dictionaries.
-
Calculate and print:
- Total units sold for each product.
- Average unit price per region.
- Most popular product (highest units sold).
- Total revenue per region.
-
Filter and print:
- How many
Keyboardunits were sold inNorth. - How many
Mouseunits were sold inSouth.
- How many
Tip: Use loops, conditionals, string methods, type conversion, and dictionaries for aggregations.