Python Practice Exercises for New Learners

Arzath AreeffArzath Areeff
2 min read

๐Ÿ”น Exercise 1: Working with Lists

Write a program that:

  • Creates a list of 5 numbers

  • Adds a new number to the list

  • Removes the second number

  • Prints the list


๐Ÿ”น Exercise 2: Conditions with Loops

Create a list of numbers from 1 to 10. Use a for loop to:

  • Print whether each number is even or odd

๐Ÿ”น Exercise 3: Tuple and Indexing

Create a tuple with the names of 4 fruits.

  • Print the first and last fruit using indexing

  • Loop through the tuple and print each fruit in uppercase


๐Ÿ”น Exercise 4: Set Operations

Create two sets:

  • set1 = {1, 2, 3, 4}

  • set2 = {3, 4, 5, 6}

Then:

  • Print the union of the sets

  • Print the intersection

  • Add 7 to set1


๐Ÿ”น Exercise 5: Dictionary and Conditionals

Create a dictionary of student marks:

marks = {
    "Alice": 85,
    "Bob": 56,
    "Charlie": 72
}

Then:

  • Print only students who passed (marks โ‰ฅ 60)

  • Add a new student "Diana" with mark 90

  • Print the average mark of all students


โœ… Answers

โœ… Exercise 1:

numbers = [10, 20, 30, 40, 50]
numbers.append(60)
del numbers[1]  # Removes the second element (20)
print(numbers)  # Output: [10, 30, 40, 50, 60]

โœ… Exercise 2:

nums = list(range(1, 11))
for num in nums:
    if num % 2 == 0:
        print(num, "is even")
    else:
        print(num, "is odd")

โœ… Exercise 3:

fruits = ("apple", "banana", "mango", "orange")
print(fruits[0])     # Output: apple
print(fruits[-1])    # Output: orange

for fruit in fruits:
    print(fruit.upper())

โœ… Exercise 4:

set1 = {1, 2, 3, 4}
set2 = {3, 4, 5, 6}

print(set1 | set2)  # Union: {1, 2, 3, 4, 5, 6}
print(set1 & set2)  # Intersection: {3, 4}
set1.add(7)
print(set1)         # Output: {1, 2, 3, 4, 7}

โœ… Exercise 5:

marks = {
    "Alice": 85,
    "Bob": 56,
    "Charlie": 72
}

for name, score in marks.items():
    if score >= 60:
        print(name, "passed with", score)

marks["Diana"] = 90

average = sum(marks.values()) / len(marks)
print("Average mark:", average)
0
Subscribe to my newsletter

Read articles from Arzath Areeff directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Arzath Areeff
Arzath Areeff

I co-founded digizen.lk to promote online safety and critical thinking. Currently, Iโ€™m developing an AI app to fight misinformation. As Founder and CEO of ideaGeek.net, I help turn startup dreams into reality, and I share tech insights and travel stories on my YouTube channels, TechNomad and Rz Omar.