[object Object]

15+ Python Assignments for Absolute Beginners (with Solutions and Explanations)

Accelerate your Python journey with 15+ practical assignments for absolute beginners. Master core concepts and start coding.

POSTED ON APRIL 1, 2025

Learning Python can feel overwhelming at first, but you can speed this process up.

How? 

By practicing writing code from day one. 

We put together a list of Python assignments for beginners exploring basic concepts in Python to help you learn faster. 

Each exercise will introduce you to a key concept, provide a step-by-step explanation, and show how it can be useful in real life. 

Jump to the one you like the most, or keep reading:

1. Printing and variables
2. User input and simple calculations
3. Basic conditional statements
4. Loops (counting to 10)
5. Checking prime numbers
6. Basic string operations
7. Finding the longest word
8. Reversing a string
9. Palindrome check
10. Finding duplicates in a list
11. Calculating discounts
12. Expense tracker
13. Employee salary calculation
14. Customer order system
15. FizzBuzz

Looking for something slightly more advanced? Check out our list of the best Python projects for beginners.

1. Printing and variables

Let’s start with the absolute basics: how to print text, store values in variables, and display them.

Every Python program needs to store and display data. This is the first step to writing meaningful code.

What is a variable?

A variable is a named storage location for a value. For example:

“Alice” is stored in name, and 25 is stored in age.

Assignment

Write a program that:

  1. Stores your name and age in variables
  2. Prints a sentence like “Hello, my name is Alice, and I am 25 years old”

This task is useful in real life when building profile pages (e.g., user registration forms), chatbots (e.g., displaying user details dynamically), and so on.

Solution

  • Assign values to name and age
  • Use print() to display the message
  • The commas inside print() allow multiple values to be displayed in one line

2. User input and simple calculations

Now that you can print text and use variables, learn how to let users enter data and perform basic calculations.

Why is this important? Because interactive programs ask users for input rather than using fixed values.

For example, you can apply this skill when building age verification systems (e.g., websites that check if you’re over 18) or interactive registration forms.

Assignment 

Write a program that:

  1. Asks the user for their name
  2. Asks the user for their birth year
  3. Calculates and displays their age

Solution

name = input("Enter your name: ")
birth_year = int(input("Enter your birth year: "))
age = 2024 - birth_year  # Assuming the current year is 2024
print("Hello", name + "! You are", age, "years old.")
  • input() allows the user to enter data
  • int() converts the input (which is a string) into a number
  • Subtract the birth year from 2024 to calculate age

3. Basic conditional statements (checking even or odd numbers)

Programs often need to make decisions. Let’s learn how to check if a number is even or odd.

Conditional statements (if, else) let programs make smart decisions instead of running in a fixed way.

This can be applied in all sorts of real-world scenarios. 

For example, if you’re building a banking app and need to add a feature that checks if an account number follows an even/odd rule. Or if you create a lottery system that generates even or odd lucky numbers.

Assignment

Write a program that:

  1. Asks the user for a number
  2. Prints “Even” if the number is even, otherwise prints “Odd”

Solution

number = int(input("Enter a number: "))
if number % 2 == 0:
    print("Even")
else:
    print("Odd")
  • Use % 2 == 0 to check if the number is divisible by 2
  • if and else allow the program to choose the correct message

4. Loops (counting to 10 using a while loop)

Sometimes, you need a program to repeat a task multiple times. Loops allow you to do this efficiently.

Without them, you would have to write the same code multiple times manually.

They also help with various functions, such as keeping score in games or sending automated reminders.

What is a while loop?

A while loop repeats a block of code as long as a condition is true.

Assignment

Write a program that prints numbers from 1 to 10 using a while loop.

Solution

count = 1

while count <= 10:

    print(count)

    count += 1  # Increase count by 1 each time
  1. Start with count = 1
  2. The loop runs while count <= 10
  3. count += 1 increases the number after each print

5. Checking prime numbers (combining loops & conditionals)

Next, let’s apply loops and conditionals together to check if a number is prime. 

This skill can help in areas like cybersecurity encryption where prime numbers are used to secure data online through cryptographic algorithms.

Assignment

Write a program that checks if a number is prime.

Solution

def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True
num = int(input("Enter a number: "))
print(is_prime(num))
  • Numbers less than 2 are not prime
  • Loop from 2 to sqrt(n), checking if n is divisible by any number
  • If it is, it’s not prime. Otherwise, it is.

6. Basic string operations (counting vowels in a sentence)

Text processing is a fundamental part of programming. Start with an easy exercise: counting vowels in a sentence.

Many real-world applications need to analyze text—for example, word counting in documents or detecting the most common letters in a language.

It can be especially useful for spell checkers, text-to-speech programs that analyze vowels in words, and similar applications.

What is a string?

A string is a sequence of characters, such as:

text = "Hello, World!"

Strings can be looped through, modified, and checked for specific letters.

Assignment

Write a function count_vowels(text) that counts and returns the number of vowels (a, e, i, o, u) in a given sentence.

Solution

def count_vowels(text):
    vowels = "aeiouAEIOU"
    count = 0
    for char in text:
        if char in vowels:
            count += 1
    return count
sentence = input("Enter a sentence: ")
print("Number of vowels:", count_vowels(sentence))
  1. Define a string vowels containing all vowel letters
  2. Loop through each character in the sentence and check if it’s a vowel
  1. If it is, increase the count
  2. Finally, return the total number of vowels

7. Finding the longest word in a sentence

Now that you can manipulate text, learn how to break down a sentence into words and find the longest one.

How can it be applied to real life?

Search engines and AI chatbots identify important words to give better responses. 

For example, features like text summarization find keywords in longer articles and return a balanced result. 

Assignment

Write a function longest_word(sentence) that returns the longest word in a given sentence.

Solution

def longest_word(sentence):
    words = sentence.split()  # Split sentence into words
    longest = words[0]  
    for word in words:
        if len(word) > len(longest):  
            longest = word
    return longest
sentence = input("Enter a sentence: ")
print("Longest word:", longest_word(sentence))
  1. .split() breaks the sentence into a list of words
  2. Assume the first word is the longest
  3. Loop through all words, checking if any are longer
  4. The longest word is returned

8. Reversing a string without built-in methods

Next, combine what you’ve learned so far to manually reverse a string. 

Many programs manipulate text data, such as reversing words in usernames or IDs. This technique is also useful for simple text encryption.

Assignment 

Write a function reverse_string(text) that:

  1. Takes a string as input
  2. Reverses the string manually, without using [::-1]
  3. Returns the reversed string

Solution

def reverse_string(text):
    reversed_text = ""
    for char in text:
        reversed_text = char + reversed_text
    return reversed_text
word = input("Enter a word: ")
print("Reversed:", reverse_string(word))

Create an empty string reversed_text to store the reversed word.

Then, loop through each character in the original string:

  • Instead of appending (+) characters at the end, add them at the front of reversed_text
  • This effectively builds the reversed version of the string

Once the loop is done, return the reversed string.

9. Checking if a word is a palindrome

You can also check if a word reads the same forward and backward.

Palindromes are used in data validation, security, and DNA sequence analysis. For example, they help with password validation (checking if passwords meet certain criteria) and genetic research (identifying palindromic sequences in DNA).

Assignment

Write a function is_palindrome(word) that checks if a word is a palindrome.

Solution

def is_palindrome(word):
    reversed_word = ""
    for char in word:
        reversed_word = char + reversed_word
    return word == reversed_word
word = input("Enter a word: ")
print("Is palindrome:", is_palindrome(word))
  • Reverse the word (as in Exercise 8)
  • Compare the original and reversed word to check if they match

10. Finding duplicates in a list

Next, practice working with lists and check for repeated elements.

There are many ways to apply this skill: e.g., to detect duplicate orders in ecommerce or add spam filters that check for repeated emails.

Assignment

Write a function find_duplicates(lst) that finds and returns a list of duplicate values.

Solution

def find_duplicates(lst):
    seen = set()
    duplicates = set()
    for num in lst:
        if num in seen:
            duplicates.add(num)
        seen.add(num)
    return list(duplicates)
numbers = [1, 2, 3, 2, 4, 5, 6, 5]
print("Duplicates:", find_duplicates(numbers))
  1. Use a set() to track seen numbers
  2. If a number is already in the set, it’s added to duplicates
  3. Return a list of duplicate numbers

11. Calculating discounts in a store

From here, you can experiment with more advanced assignments connected to real-world use cases.

For instance, imagine you’re building an online store and need to apply a discount to products dynamically.

Assignment 

Write a function apply_discount(price, discount_percent) that:

  1. Takes the original price of a product.
  2. Takes a discount percentage (e.g., 10 for 10%).
  3. Calculates and returns the final price after applying the discount.

Solution

def apply_discount(price, discount_percent):
    if price < 0 or discount_percent < 0 or discount_percent > 100:
        return "Invalid input"
    discount_amount = (discount_percent / 100) * price
    return round(price - discount_amount, 2)
# Example usage
print(apply_discount(100, 20))  # Output: 80.0
print(apply_discount(50, 10))   # Output: 45.0
print(apply_discount(200, 50))  # Output: 100.0
  • Check for invalid inputs (negative values, discount over 100%)
  • Calculate the discount amount using (discount_percent / 100) * price
  • Subtract the discount from the original price
  • The result is rounded to 2 decimal places for realistic pricing

12. Expense tracker (calculating total and average expenses)

Managing finances is another essential skill. 

This assignment helps you build a simple expense tracker that calculates how much you’ve spent and the average expense per item.

What is a list?

A list stores multiple values in a single variable. Example:

expenses = [20, 15.5, 10, 5]

Lists make it easy to store and analyze multiple numbers.

Assignment 

Write a function track_expenses(expenses) that calculates:

  1. The total amount spent
  2. The average expense per item

Solution

def track_expenses(expenses):
    if not expenses:
        return "No expenses recorded."
    total_spent = sum(expenses)
    average_expense = total_spent / len(expenses)
    return round(total_spent, 2), round(average_expense, 2)
expenses = [20, 15.5, 10, 5]
print("Total and average expenses:", track_expenses(expenses))
  1. Check if the list is empty (no expenses recorded)
  2. Calculate total expenses using sum(expenses)
  3. Calculate the average expense by dividing the total by the number of items
  4. Round the results for better readability

13. Employee salary calculation

Companies calculate employee salaries based on hours worked and additional bonuses. Write a function to automate this calculation.

Assignment

Write a function calculate_salary(hours_worked, hourly_rate, bonus=0) that calculates an employee’s salary, including optional bonuses.

Solution

def calculate_salary(hours_worked, hourly_rate, bonus=0):
    if hours_worked < 0 or hourly_rate < 0 or bonus < 0:
        return "Invalid input"
    salary = (hours_worked * hourly_rate) + bonus
    return round(salary, 2)
print(calculate_salary(40, 15))       # Output: 600.0
print(calculate_salary(40, 15, 100))  # Output: 700.0
  1. Check for invalid input (negative values)
  2. Multiply hours worked by hourly rate
  3. If a bonus is provided, it’s added to the salary
  4. The result is rounded for better readability

14. Customer order system (ecommerce simulation)

Every online store needs a system to process orders. Try building a simple order calculator using dictionaries.

What is a dictionary?

A dictionary stores data in key-value pairs. For example:

menu = {"burger": 5, "fries": 2.5, "soda": 1.5}

Here, “burger” is the key, and 5 is its price.

Assignment

Write a function place_order(order_items, menu_prices) that calculates the total cost of an order.

Solution

def place_order(order_items, menu_prices):
    total_cost = 0
    for item, quantity in order_items.items():
        if item in menu_prices:
            total_cost += menu_prices[item] * quantity
        else:
            return f"Error: {item} is not available on the menu."
    return round(total_cost, 2)
menu = {"burger": 5, "fries": 2.5, "soda": 1.5}
order = {"burger": 2, "fries": 1}
print("Total order cost:", place_order(order, menu))  
# Output: 12.5
  1. Loop through order_items, checking if each item exists in menu_prices
  1. If an item is found, its price is multiplied by the quantity ordered
  2. If an item is not found, an error message is returned
  3. The total cost is rounded and returned

15. FizzBuzz (a classic interview question)

The FizzBuzz challenge is a common coding interview question that checks your problem-solving skills and ability to use Python loops.

Assignment

Write a function fizz_buzz(n) that prints numbers from 1 to n, but:

  • Prints “Fizz” if the number is divisible by 3
  • Prints “Buzz” if the number is divisible by 5
  • Prints “FizzBuzz” if the number is divisible by both 3 and 5

Solution

def fizz_buzz(n):
    for i in range(1, n + 1):
        if i % 3 == 0 and i % 5 == 0:
            print("FizzBuzz")
        elif i % 3 == 0:
            print("Fizz")
        elif i % 5 == 0:
            print("Buzz")
        else:
            print(i)
fizz_buzz(15)
  1. Loop through numbers from 1 to n
  2. Check divisibility using the modulo operator (%)
  3. The correct word (“Fizz”, “Buzz”, or “FizzBuzz”) is printed accordingly

Other beginner Python exercises you can try

Looking for more Python exercises with solutions and guidelines? Here are other free resources you can try: 

How to find and solve beginner Python assignments

The examples we shared in this guide can help you acquire practical skills. But, the best way to learn Python is by combining theory with practice and getting useful feedback.

If you’re looking for something more structured, Mimo’s Python Career Path is right up your alley. It combines bite-sized lessons with interactive assignments and instant AI feedback.

You’ll move from one topic to another by learning theory and solving challenges within Mimo’s interactive platform.

The platform will help you learn each concept through a mix of text and simple assignments. 

As you progress, you’ll be collecting points and building up your streaks.

Soon enough, you’ll start solving more complex problems like:

  • Creating a to-do list app
  • Building a food order system
  • Putting together a Star Wars API

And more!

The fastest way to learn Python is by coding

These Python exercises guide you from basic concepts like variables and printing to more advanced topics such as functions, loops, and dictionaries. 

Each exercise tackles fundamental programming skills while demonstrating their real-world applications. 

The key to mastering Python? Consistent practice combined with useful feedback. 

If you’re looking to learn Python fast, try Mimo’s Python Career Path, which offers a fun, effective learning experience and a certificate.

Henry Ameseder

AUTHOR

Henry Ameseder

Henry is the COO and a co-founder of Mimo. Since joining the team in 2016, he’s been on a mission to make coding accessible to everyone. Passionate about helping aspiring developers, Henry creates valuable content on programming, writes Python scripts, and in his free time, plays guitar.

Learn to code and land your dream job in tech

Start for free