## Blog Detail

### Python Custom Functions Exercises

• Define a function that prints Hello Python! on the console.

```                ```'' print_hello_python():
print("Hello Python!")``````
• Call the function.

```                ```def print_hello_python():
print("Hello Python!")

''``````
• Modify the function that accepts a string and prints it on the console.

```                ```def print_string(''):
print(input_string)

print_string("Hello Python!")
``````
• This function takes a number and doubles it. Return the doubled value.

```                ```def double_number(number):
result = number * 2
'' result

result = double_number(5)

print('The doubled number is:', result)``````
• Combine the math operation and return into a single line instead of two lines.

```                ```def double_number(number):
# result = number * 2
''

result = double_number(5)

print('The doubled number is:', result)``````
• How does this function work?

```                ```def is_positive(number):
if number > 0:
return True
else:
return False``````
• What is the output of this code?

```                ```def check_stock_availability(quantity):
if quantity > 0:
return "Product is in stock."
else:
return "Product is out of stock."

result = check_stock_availability(12)
print(result)``````
• What is the output of this code?

```                ```def check_password_strength(password):
else:

print(result)``````
• What is the output of this code?

```                ```def calculate_shipping_cost(weight, destination):
if weight <= 0:
return "Invalid weight"

if destination == "domestic":
shipping_cost = 0.5 * weight
return f"Domestic shipping: \${shipping_cost}"

if destination == "international":
shipping_cost = 1.5 * weight
return f"International shipping: \${shipping_cost}"

return "Invalid destination"

weight = 2.5
destination = "international"
result = calculate_shipping_cost(weight, destination)

print(result)``````
• What does this function return?

```                ```def check_number(number):
if number > 0:
return 'Positive'
elif number < 0:
return 'Negative'

return 'Zero'

result = check_number(0)
print(result)``````
• What is the output of this code?

```                ```def calculate_shipping_cost(weight, destination):
if weight <= 0:
return "Invalid weight"

if destination == "domestic":
shipping_cost = 0.5 * weight
return f"Domestic shipping: \${shipping_cost}"

if destination == "international":
shipping_cost = 1.5 * weight
return f"International shipping: \${shipping_cost}"

return "Invalid destination."

weight = 2
destination = "internationl"
result = calculate_shipping_cost(weight, destination)

print(result)``````
• This function generates a username based on first name, last name and separator.
What is the output of this code?

```                ```def generate_username(first_name, last_name, separator):

first_name = 'Emma'
last_name = 'Smith'

print(result)``````
• This function generates a username based on the first name, last name, and separator.
Modify the function to utilize an underline as the optional value.

```                ```def generate_username(first_name, last_name, ''):

first_name = 'Emma'
last_name = 'Smith'

print(result)``````
• What is the output of this code?

```                ```def generate_username(first_name, last_name, separator = '_'):

first_name = 'Emma'
last_name = 'Smith'

print(result)``````
• What is the output of this code?

```                ```def generate_username(first_name, last_name, separator = '_'):

first_name = 'Emma'
last_name = 'Smith' 