new test
This commit is contained in:
parent
0b77bb8941
commit
b263b1e8b4
1 changed files with 21 additions and 0 deletions
21
test/ruby/23.in
Normal file
21
test/ruby/23.in
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# test_basic.py
|
||||
def factorial(n):
|
||||
"""Calculate factorial recursively"""
|
||||
if n <= 1:
|
||||
return 1
|
||||
else:
|
||||
return n * factorial(n - 1)
|
||||
|
||||
def is_prime(num):
|
||||
if num < 2:
|
||||
return False
|
||||
for i in range(2, int(num ** 0.5) + 1):
|
||||
if num % i == 0:
|
||||
return False
|
||||
return True
|
||||
|
||||
# Test the functions
|
||||
print(f"Factorial of 5: {factorial(5)}")
|
||||
|
||||
for n in [2, 3, 4, 17, 21]:
|
||||
print(f"{n} is prime: {is_prime(n)}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue