# Factorial Function (Using Recursion)
def factorial(n):
# Handle invalid input
if not isinstance(n, int) or n < 0:
return "Error: Factorial is only defined for non-negative integers."
# Base cases: 0! and 1! both return 1
elif n in (0, 1):
return 1
# Recursive case: n! = n * (n - 1)!
else:
return n * factorial(n - 1)
# Calculate factorial of a number between 9 and 13
number = 11
result = factorial(number)
# Display the outcome with a message
if isinstance(result, int):
print(f"The factorial of {number} is {result}.")
else:
print(result)
# Iterating Over a List (Numbers)
numbers = [1, 2, 3, 4, 5]
for num in numbers:
print(num)
# Iterating Through a List (Colors) with a Message
colors = ["red", "blue", "green", "yellow"]
for color in colors:
print(color)
# Using `continue` and `break` in a Loop
numbers = [1, 2, 3, 4, 5]
for num in numbers:
if num == 3:
continue # Skip when the number is 3
elif num == 5:
break # Exit the loop when 5 is encountered
print(num)