mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-19 10:26:15 +01:00
use elsif instead
This commit is contained in:
parent
d3d66e1ef1
commit
6e70556e39
1 changed files with 4 additions and 5 deletions
|
@ -9,12 +9,11 @@
|
|||
def factorial(number)
|
||||
if number < 0
|
||||
"Please check your input number! The given number is a negative number."
|
||||
else
|
||||
if number == 0
|
||||
elsif number == 0
|
||||
"The factorial of #{number} is 1."
|
||||
else
|
||||
"The factorial of #{number} is #{(1..number).inject(:*)}."
|
||||
end
|
||||
result = (1..number).inject(:*)
|
||||
"The factorial of #{number} is #{result}."
|
||||
end
|
||||
rescue
|
||||
"Error: Please provide integer only!"
|
||||
|
|
Loading…
Reference in a new issue