def rectangle_area(length, width):
area = length * width
perimeter = 2 * (length + width)
return area, perimeter
# Call the function with specific values for length and width
length = 5
width = 3
area, perimeter = rectangle_area(length, width)
# Print the results
print("Area:", area)
print("Perimeter:", perimeter)
Area: 15 Perimeter: 16
def is_even(number):
if number % 2 == 0:
return "Even"
else:
return "Odd"
# Call the function with a specific number
number = 4
result = is_even(number)
# Print the result
print(f"The number {number} is {result}.")
The number 4 is Even.
def count_case_letters(input_string):
uppercase_count = 0
lowercase_count = 0
for char in input_string:
if char.isupper():
uppercase_count += 1
elif char.islower():
lowercase_count += 1
return uppercase_count, lowercase_count
# Sample string
sample_string = "CUNY sps"
# Call the function with the sample string
upper_count, lower_count = count_case_letters(sample_string)
# Print the results
print("# of upper case characters:", upper_count)
print("# of lower case characters:", lower_count)
# of upper case characters: 4 # of lower case characters: 3
def sum_list_numbers(numbers):
total = sum(numbers)
return total
# Sample list of numbers
numbers_list = [1, 2, 3, 4, 5]
# Call the function with the sample list
result = sum_list_numbers(numbers_list)
# Print the result
print("Sum of numbers:", result)
Sum of numbers: 15
global_variable = 10
def example_function():
local_variable = 5
print("Global variable:", global_variable)
print("Local variable:", local_variable)
example_function()
print("Outside the function, global variable:", global_variable)
# The local_variable is not accessible outside the function.
Global variable: 10 Local variable: 5 Outside the function, global variable: 10
def multiply_with_unknown(value):
unknown_number = 7 # You can replace this with any desired number
result = value * unknown_number
return result
# Call the function with a specific value
value = 5
result = multiply_with_unknown(value)
# Print the result
print(f"{value} multiplied by the unknown number is {result}.")
5 multiplied by the unknown number is 35.