Welcome to Python World!

Learn Coding Step by Step 🚀

A fun beginner programming course for young programmers
Created by Geta Ba / GETCOM

📌 Example 51: Create a Simple Function

A function is a reusable block of code that performs a task.

🐍 Python Code



# EXAMPLE 51
# Create and Call Function


def message():

    print("Welcome to Python Functions")


message()


🤖 Python Output

Welcome to Python Functions 🎉

⭐ Challenge: Create a function that prints your name.

👋 Example 52: Greeting Function

Functions can receive information using parameters.

🐍 Python Code



# EXAMPLE 52
# Greeting Function


def greeting(name):

    print("Hello", name)


greeting("Gech")


🤖 Python Output

Hello Gech 👋

⭐ Challenge: Change the name to Abebe and Saba.

➕ Example 53: Addition Function

A function can receive numbers and return a result.

🐍 Python Code



# EXAMPLE 53
# Add Two Numbers


def add(a,b):

    return a+b



result = add(10,20)


print("Sum =", result)


🤖 Python Output

Sum = 30

⭐ Challenge: Create a function that adds three numbers.

➖ Example 54: Subtraction Function

Functions can perform mathematical operations.

🐍 Python Code



# EXAMPLE 54
# Subtraction Function


def subtract(a,b):

    return a-b



answer = subtract(50,20)



print("Difference =", answer)


🤖 Python Output

Difference = 30

⭐ Challenge: Subtract 100 and 45.

✖ Example 55: Multiplication Function

Functions make repeated calculations easier.

🐍 Python Code



# EXAMPLE 55
# Multiplication Function


def multiply(a,b):

    return a*b



result = multiply(5,6)



print("Multiplication =", result)


🤖 Python Output

Multiplication = 30 ⭐

🚀 Project: Create a function to calculate the area of a rectangle.

➗ Example 56: Division Function

A function can divide two numbers and return the answer.

🐍 Python Code



# EXAMPLE 56
# Division Function


def divide(a,b):

    return a / b



result = divide(20,5)



print("Division =", result)


🤖 Python Output

Division = 4.0

⭐ Challenge: Create a function to divide 100 by 10.

🔢 Example 57: Even or Odd Function

A function can check whether a number is even or odd.

🐍 Python Code



# EXAMPLE 57
# Even or Odd Function


def check_number(number):

    if number % 2 == 0:

        return "Even Number"

    else:

        return "Odd Number"



result = check_number(15)



print(result)


🤖 Python Output

Odd Number

⭐ Challenge: Test numbers 8, 11, 20, and 35.

🎓 Example 58: Student Grade Function

A function can automatically calculate student grades.

🐍 Python Code



# EXAMPLE 58
# Student Grade Function


def grade(mark):

    if mark >= 90:

        return "A"

    elif mark >= 70:

        return "B"

    elif mark >= 50:

        return "C"

    else:

        return "F"



result = grade(85)



print("Grade =", result)


🤖 Python Output

Mark = 85


Grade = B ⭐

⭐ Challenge: Test marks 95, 75, 45.

📊 Example 59: Average Function

A function can calculate the average of numbers.

🐍 Python Code



# EXAMPLE 59
# Average Function


def average(a,b,c):

    total = a+b+c

    avg = total/3

    return avg



result = average(80,90,70)



print("Average =", result)


🤖 Python Output

Marks = 80, 90, 70


Average = 80.0

🚀 Project: Create a function that calculates five subject averages.

🔤 Example 60: Vowel Checker Function

A function can identify vowels and consonants.

🐍 Python Code



# EXAMPLE 60
# Vowel Checker Function


def check_letter(letter):

    letter = letter.lower()


    if letter in "aeiou":

        return "Vowel"

    else:

        return "Consonant"



result = check_letter("A")



print("Letter A is", result)


🤖 Python Output

Letter A is

Vowel 🔤

⭐ Challenge: Check letters A, E, K, M, and U.

📈 Example 61: Maximum Number Function

A function can find the largest number from given values.

🐍 Python Code



# EXAMPLE 61
# Maximum Number Function


def maximum(a,b,c):

    if a > b and a > c:

        return a

    elif b > c:

        return b

    else:

        return c



result = maximum(20,50,30)


print("Maximum =", result)


🤖 Python Output

Numbers = 20, 50, 30


Maximum = 50 📈

⭐ Challenge: Find the maximum number from 100, 45, and 75.

📉 Example 62: Minimum Number Function

A function can find the smallest number from values.

🐍 Python Code



# EXAMPLE 62
# Minimum Number Function


def minimum(a,b,c):

    if a < b and a < c:

        return a

    elif b < c:

        return b

    else:

        return c



result = minimum(20,50,30)



print("Minimum =", result)


🤖 Python Output

Numbers = 20, 50, 30


Minimum = 20 📉

⭐ Challenge: Find the minimum number from 90, 40, and 60.

🔁 Example 63: Loop Inside Function

A function can repeat actions using loops.

🐍 Python Code



# EXAMPLE 63
# Loop Function


def print_numbers():

    for i in range(1,6):

        print(i)



print_numbers()


🤖 Python Output

1

2

3

4

5 🔁

⭐ Challenge: Create a function that prints numbers from 1 to 20.

⭐ Example 64: Factorial Function

A function can calculate factorial values using loops.

🐍 Python Code



# EXAMPLE 64
# Factorial Function


def factorial(number):

    result = 1


    for i in range(1, number+1):

        result = result * i


    return result



answer = factorial(5)



print("Factorial =", answer)


🤖 Python Output

5! = 5×4×3×2×1


Factorial = 120 ⭐

🚀 Challenge: Find factorial of 7.

🔢 Example 65: Prime Number Function

A function can check whether a number is prime.

🐍 Python Code



# EXAMPLE 65
# Prime Number Function


def prime(number):

    if number <= 1:

        return "Not Prime"


    for i in range(2,number):

        if number % i == 0:

            return "Not Prime"


    return "Prime Number"



result = prime(7)



print(result)


🤖 Python Output

Number = 7


Prime Number ✅

⭐ Challenge: Test numbers 2, 9, 11, and 15.

🧮 Example 66: Simple Calculator Function

A function can perform different mathematical operations.

🐍 Python Code



# EXAMPLE 66
# Calculator Function


def calculator(a,b,operation):

    if operation == "+":

        return a+b

    elif operation == "-":

        return a-b

    elif operation == "*":

        return a*b

    elif operation == "/":

        return a/b

    else:

        return "Invalid Operation"



result = calculator(20,5,"*")



print("Answer =", result)


🤖 Python Output

20 * 5


Answer = 100 🧮

🚀 Challenge: Create a calculator that accepts user input.

💰 Example 67: Salary Calculator Function

A function can calculate total salary including bonus.

🐍 Python Code



# EXAMPLE 67
# Salary Calculator


def salary_calculator(basic,bonus):

    total = basic + bonus

    return total



salary = salary_calculator(5000,1000)



print("Total Salary =", salary)


🤖 Python Output

Basic Salary = 5000

Bonus = 1000


Total Salary = 6000 💰

⭐ Challenge: Add tax deduction to the salary calculator.

🛒 Example 68: Shopping Cost Function

A function can calculate product total cost.

🐍 Python Code



# EXAMPLE 68
# Shopping Cost


def shopping(price,quantity):

    total = price * quantity

    return total



cost = shopping(50,4)



print("Total Cost =", cost)


🤖 Python Output

Price = 50

Quantity = 4


Total Cost = 200 🛒

🚀 Project: Add discount and tax calculation.

👨‍🎓 Example 69: Student Registration Function

Functions can manage student information.

🐍 Python Code



# EXAMPLE 69
# Student Registration


students = []


def register_student(name):

    students.append(name)

    return "Student Added Successfully"



print(register_student("Gech"))

print(register_student("Abebe"))


print(students)


🤖 Python Output

Student Added Successfully

Student Added Successfully


['Gech', 'Abebe'] 👨‍🎓

⭐ Challenge: Create functions for search and delete student.

🚀 Example 70: Complete Mini Project Using Functions

A small banking system using multiple functions.

🐍 Python Code



# EXAMPLE 70
# Mini Banking System


balance = 0



def deposit(amount):

    global balance

    balance += amount



def withdraw(amount):

    global balance

    if amount <= balance:

        balance -= amount

    else:

        print("Insufficient Balance")



def show_balance():

    print("Balance =", balance)




deposit(1000)

withdraw(300)

show_balance()


🤖 Python Output

Deposit = 1000

Withdraw = 300


Balance = 700 💰

🏆 Final Challenge: Create a complete system using functions:
✔ Student Management System
✔ ATM System
✔ Shop Management System