Skip to main content

Command Palette

Search for a command to run...

Hands-On Python Exercise: Understanding Basic Functions

Published
2 min readView as Markdown
Hands-On Python Exercise: Understanding Basic Functions
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 💻

🔹 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 sum.


🔹 Question 3: Check Even or Odd

Write a function called is_even that takes a number and returns True if it's even, otherwise False.


🔹 Question 4: Find the Square

Write a function called square that takes a number and returns its square.


🔹 Question 5: Convert Celsius to Fahrenheit

Write a function called celsius_to_fahrenheit that converts a temperature from Celsius to Fahrenheit using the formula:

F = C * 9/5 + 32

🧠 Answers


Answer 1: Greet User

def greet_user(name):
    print(f"Hello, {name}!")

# Example call
greet_user("Areeff")

Answer 2: Add Two Numbers

def add_numbers(a, b):
    return a + b

# Example call
result = add_numbers(3, 5)
print(result)  # Output: 8

Answer 3: Check Even or Odd

def is_even(number):
    return number % 2 == 0

# Example call
print(is_even(4))  # Output: True
print(is_even(7))  # Output: False

Answer 4: Find the Square

def square(num):
    return num * num

# Example call
print(square(6))  # Output: 36

Answer 5: Celsius to Fahrenheit

def celsius_to_fahrenheit(celsius):
    return celsius * 9/5 + 32

# Example call
print(celsius_to_fahrenheit(0))   # Output: 32.0
print(celsius_to_fahrenheit(100)) # Output: 212.0
H

This is concise and useful

1

Python

Part 9 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

Python Lab Exercise Made Simple for Beginners

Exercise 1: Basic Calculator Lab Exercise Instructions: Create a new Python file called calculator.py Implement the calculator program following these steps: First, ask the user to input an operator Then, ask for two numbers Use conditional stat...

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.”