Created
January 23, 2019 08:07
-
-
Save ChantalDemissie/ae5f33e125c03c1d168a192723e89c4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# problem 1 | |
puts "hello there please enter 5 names seperated by spaces" | |
loop do | |
names = gets.chomp.upcase.split | |
if names.length >= 5 | |
puts names[0..4] | |
break | |
else | |
puts "Please enter at least 5 names" | |
end | |
end | |
# problem 2 | |
truthinesses = [] | |
3.times do | |
puts "please enter true or false" | |
truthiness = gets.chomp | |
truthiness = truthiness == "true" ? true : false | |
truthinesses.push(truthiness) | |
end | |
all_true = true | |
truthinesses.each do |truthiness| | |
if truthiness == false | |
all_true = false | |
end | |
end | |
if all_true | |
puts "YES" | |
else | |
puts "NO" | |
end | |
# problem 3 | |
fire = [ | |
"firetruck", | |
"fire drill", | |
"fire hydrant", | |
"firefighter", | |
"fireproof", | |
"fire station", | |
"fire hose" | |
] | |
fire.each do |string| | |
print "#{string[4..-1].lstrip}, " | |
end | |
puts "" | |
# problem 4 | |
puts "how much money did you spend on four people?" | |
money_spent = [] | |
4.times do | |
amount = gets.chomp.to_f | |
money_spent.push(amount) | |
end | |
total = 0.0 | |
money_spent.each do |amount| | |
total += amount | |
end | |
puts "$%.2f" % total | |
# problem 5 | |
numbers = [] | |
5.times do | |
random_number = rand(1..10) | |
numbers.push(random_number) | |
puts random_number**2 | |
end | |
# problem 6 | |
numbers = [] | |
5000.times do | |
random_number = rand(0.0...1.0) | |
numbers.push(random_number) | |
end | |
total = 0.0 | |
numbers.each do |number| | |
total += number | |
end | |
mean = total / numbers.length | |
puts mean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Chantal,
Thanks for submitting (and sorry for the delayed feedback)! Excellent work on these exercises, here is my feedback.
For example on an input of
print them out like this? (hint, the solution would involve a fencepost approach)
true
andfalse
into the array, instead of just the string versions of them.Hope you're enjoying Ada!
Best,
Brooks