spark: add number analyzer script for verification
This commit is contained in:
1 parent
5010821e1d
commit
c4bc3a19c3
1 file changed
+38
@@ -0,0 +1,38 @@
|
||||
#!/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))
|
||||
Reference in new issue
Block a user