Files
troupe-standup/wizard-work/spark/number_analyzer.py
T

38 lines
916 B
Python

#!/usr/bin/env python3
"""Simple verification script that counts and analyzes a number."""
def analyze_number(n):
"""Analyze a number and return properties."""
result = {
"value": n,
"is_prime": is_prime(n),
"is_even": n % 2 == 0,
"fizz_buzz": fizz_buzz(n)
}
return result
def is_prime(num):
"""Check if a number is prime."""
if num < 2:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
def fizz_buzz(num):
"""Return fizz, buzz, or the number as string."""
if num % 15 == 0:
return "fizz-buzz"
elif num % 3 == 0:
return "fizz"
elif num % 5 == 0:
return "buzz"
else:
return str(num)
if __name__ == "__main__":
import json
test_value = 42
result = analyze_number(test_value)
print(json.dumps(result, indent=2))