some progress
This commit is contained in:
parent
5c9abff73f
commit
f92f5ef7f6
11 changed files with 235 additions and 4 deletions
|
|
@ -1 +1 @@
|
|||
print(x, y)
|
||||
print(x, y, "\n")
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
for i in items
|
||||
print(i)
|
||||
print(i, "\n")
|
||||
end
|
||||
|
|
|
|||
23
test/ruby/23.out
Normal file
23
test/ruby/23.out
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
def factorial(n)
|
||||
"""Calculate factorial recursively"""
|
||||
if n <= 1
|
||||
return 1
|
||||
else
|
||||
return n * factorial(n - 1)
|
||||
end
|
||||
end
|
||||
def is_prime(num)
|
||||
if num < 2
|
||||
return false
|
||||
end
|
||||
for i in 2...Integer(num ** 0.5) + 1
|
||||
if num % i == 0
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
print("Factorial of 5: #{factorial(5)}", "\n")
|
||||
for n in [2, 3, 4, 17, 21]
|
||||
print("#{n} is prime: #{is_prime(n)}", "\n")
|
||||
end
|
||||
20
test/ruby/24.in
Normal file
20
test/ruby/24.in
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
def calculate_bmi(weight, height):
|
||||
bmi = weight / (height ** 2)
|
||||
|
||||
if bmi < 18.5:
|
||||
category = "Underweight"
|
||||
else:
|
||||
if bmi < 25:
|
||||
category = "Normal"
|
||||
else:
|
||||
if bmi < 30:
|
||||
category = "Overweight"
|
||||
else:
|
||||
category = "Obese"
|
||||
|
||||
return f"BMI: {bmi}, Category: {category}"
|
||||
|
||||
# Test
|
||||
print(calculate_bmi(70, 1.75))
|
||||
print(calculate_bmi(90, 1.80))
|
||||
print(calculate_bmi(50, 1.65))
|
||||
20
test/ruby/24.out
Normal file
20
test/ruby/24.out
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
def calculate_bmi(weight, height)
|
||||
bmi = weight / height ** 2
|
||||
if bmi < 18.5
|
||||
category = "Underweight"
|
||||
else
|
||||
if bmi < 25
|
||||
category = "Normal"
|
||||
else
|
||||
if bmi < 30
|
||||
category = "Overweight"
|
||||
else
|
||||
category = "Obese"
|
||||
end
|
||||
end
|
||||
end
|
||||
return "BMI: #{bmi}, Category: #{category}"
|
||||
end
|
||||
print(calculate_bmi(70, 1.75), "\n")
|
||||
print(calculate_bmi(90, 1.80), "\n")
|
||||
print(calculate_bmi(50, 1.65), "\n")
|
||||
Loading…
Add table
Add a link
Reference in a new issue