Skip to main content

Command Palette

Search for a command to run...

Python Practice Exercises for New Learners

Published
•2 min read•View as Markdown
Python Practice Exercises for New Learners
A
I co-founded🫆digizen (fighting internet chaos 🧠), building an AI app to tackle misinformation, and running ideaGeek to turn “I have an idea” into real startups. I also share tech + travel on YouTube (TechNomad & Rz Omar). I touch grass too 🌱… but mostly to debug life 💻

🔹 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)

Python

Part 8 of 10

I break down Python basics with clear explanations and practical exercises. Whether you're a beginner or looking to refresh your skills, follow along to strengthen your Python fundamentals through hands-on practice. Let's code and grow together!

Up next

Hands-On Python Exercise: Understanding Basic Functions

🔹 Question 1: Greet User Write a function called greet_user that takes a name as input and prints a greeting message like "Hello, Areeff!". 🔹 Question 2: Add Two Numbers Write a function called add_numbers that takes two numbers and returns their ...

More from this blog

T

TechNomad

46 posts

TechNomad is mostly coding exercises, not long boring explanations 😌. I share what I teach and learn through hands-on problems—mainly for my students, but anyone can jump in. If you learn by doing (and breaking things), you’ll fit right in. Less theory, more “try this and see what happens.”