24-sep intro to python and basic syntax

 24-sep intro to python and basic syntax



Objective LAB 1: Write a Python function greet_user(name) that accepts the user's name as a parameter and returns a greeting message. Input: The function will accept a single parameter name which is a string. Output: The function should return "Hello, !" where is the value passed as the parameter. Constraint The input should be a non-empty string. The name will not contain any special characters or numbers.

def greet_username(name):
    if isinstance(name,str)and name.isalpha() and name:
        return f"Hello,{name}!"
    else:
            return "Invalid input.please provide a valid name."
print(greet_username("Alice"))

LAB 2 : Write a Python function | calculate age(birth year) that takes the | birth year as input and returns the | current age based on the current year | 2023. | Input: | The function takes an integer | birth_year as input. | Output: | The function returns an integer | representing the user's age. | | | | Constraint | The input birth year will be a positive | integer between 1900 and 2023. The output should be a non-negative | integer. |

def calculate_age(birth_year):
    current_year = 2023
    if isinstance(birth_year,int) and birth_year>0 and birth_year <=current_year:
        return current_year - birth_year
    else:
        return "invalid birth year.Please provide a valid year."
print(calculate_age(1990)) 

LAB 3 : Write a Python function add_numbers(num?, num?) that takes two integers as input and returns their sum. Input: The function takes two integers num1 and num2. Output: The function returns the sum of num1 and num2. Constraint num and num2 will be integers between -100000 and 100000.

def add_numbers(num1,num2):
    if isinstance(num1,int) and isinstance(num2,int):
        return num1+num2
    else:
        return "Invalid input,please provide two integers."
print(add_numbers(5, 3))