Skip to content

Instantly share code, notes, and snippets.

@ChantalDemissie
Created January 23, 2019 08:07
Show Gist options
  • Save ChantalDemissie/ae5f33e125c03c1d168a192723e89c4b to your computer and use it in GitHub Desktop.
Save ChantalDemissie/ae5f33e125c03c1d168a192723e89c4b to your computer and use it in GitHub Desktop.
# 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
@brookskindle
Copy link

Hi Chantal,

Thanks for submitting (and sorry for the delayed feedback)! Excellent work on these exercises, here is my feedback.

  • For exercise 1, we want to print all the names of the friends on one line as if they appeared in a sentence.
    For example on an input of
    What are the names of your friends?
    Me
    Myself
    I
    You would print something like
    Your friends are: Me, Myself, and I
    
    How would you change your approach such that you could loop over your friend names and
    print them out like this? (hint, the solution would involve a fencepost approach)
  • Good work on line 18, pushing the actual values of true and false into the array, instead of just the string versions of them.

Hope you're enjoying Ada!

Best,
Brooks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment