# Recursion Hack - Factorial Function
def factorial(n):
"""Calculates the factorial of a non-negative integer n."""
if not isinstance(n, int) or n < 0: # Handle invalid input
return "Error: Factorial is only defined for non-negative integers."
elif n == 0 or n == 1: # Base cases
return 1
else:
return n * factorial(n - 1) # Recursive call
# Example Usage
number = 11
result = factorial(number)
# Display the result with a custom message
if isinstance(result, int):
print(f"The factorial of {number} is {result}.")
else:
print(result)
# Iterating Over a List Hack
numbers = [1, 2, 3, 4, 5]
for number in numbers: # Print each number in the list
print(number)
# Iterating Over a List with Colors Hack
colors = ["red", "blue", "green", "yellow"]
for color in colors: # Print each color in the list
print(color)
# Breaking Loops Hack
numbers = [1, 2, 3, 4, 5]
for number in numbers:
if number == 3:
continue # Skip the number 3
elif number == 5:
break # Stop the loop when 5 is encountered
print(number)
The factorial of 11 is 39916800.
1
2
3
4
5
red
blue
green
yellow
1
2
4