From b70460915d91a3ecae39e6ee17707d7d29792de4 Mon Sep 17 00:00:00 2001 From: "Mr.Perfect 092" <135037455+stephan-maina@users.noreply.github.com> Date: Fri, 1 Sep 2023 22:50:42 +0300 Subject: [PATCH] Update functions.py --- lib/functions.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/functions.py b/lib/functions.py index 9d84754d7..ad9c55ae6 100644 --- a/lib/functions.py +++ b/lib/functions.py @@ -1,16 +1,32 @@ -#!/usr/bin/env python3 +# lib/functions.py def greet_programmer(): - pass + print("Hello, programmer!") def greet(name): - pass + print("Hello, {}!".format(name)) def greet_with_default(name="programmer"): - pass + print("Hello, {}!".format(name)) def add(num1, num2): - pass + return num1 + num2 def halve(number): - pass + if not isinstance(number, (int, float)): + return None + + return number / 2 + +# Testing the methods +if __name__ == "__main__": + greet_programmer() + greet("Stephan Maina") + greet_with_default("Bat-Tziyon Mbiki") + greet_with_default() + result = add(10, 5) + print("The sum is:", result) + halved_value = halve(20) + print("Half of 20 is:", halved_value) + invalid_result = halve("two") + print("Invalid result:", invalid_result)