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




