Skip to content

Instantly share code, notes, and snippets.

@gabericharde
Created August 30, 2016 17:04
Show Gist options
  • Save gabericharde/e0af014f837a49be37f7836e01c41a62 to your computer and use it in GitHub Desktop.
Save gabericharde/e0af014f837a49be37f7836e01c41a62 to your computer and use it in GitHub Desktop.
puts "Please provide a number between 1 and 10:"
num = gets.chomp!.to_i
if (num < 10) && (num > 1)
string = "#{num} * "
loop do
if num == 1
string.concat("#{num}")
break
end
num = num - 1
string.concat("#{num} * ")
end
puts string
else
puts "Please try again and provide a number between 1 and 10!"
end
# suggested way to get factorial result:
# puts (1..num).inject(:*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment