Last active
September 27, 2015 19:39
-
-
Save kdefliese/d41bfa65612934c3ad8c to your computer and use it in GitHub Desktop.
Homework for 9/25
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
# bottles of beer program | |
num = 99 | |
while num > 0 | |
puts "#{num} bottles of beer on the wall, #{num} bottles of beer!" | |
num -= 1 | |
puts "Take one down, pass it around, #{num} bottles of beer on the wall!" | |
end | |
# grandma program | |
puts "Say something to grandma:" | |
said = gets.chomp | |
bye_count = 0 | |
while bye_count < 2 | |
if said != said.upcase | |
bye_count = 0 | |
puts "HUH?! SPEAK UP SONNY!" | |
puts "Say something to grandma:" | |
said = gets.chomp | |
elsif said != "BYE" | |
bye_count = 0 | |
year = rand(1930..1950) | |
puts "NO, NOT SINCE #{year}!" | |
puts "Say something to grandma:" | |
said = gets.chomp | |
elsif said == "BYE" | |
bye_count += 1 | |
puts "WHAT DID YOU SAY, DEAR?" | |
puts "Say something to grandma:" | |
said = gets.chomp | |
end | |
end | |
puts "BYE NOW!" | |
# leap year program | |
puts "Give me a starting year:" | |
first_year = gets.chomp.to_i | |
puts "Ok, now give me an ending year:" | |
last_year = gets.chomp.to_i | |
years = (first_year..last_year).to_a | |
leap_years = [] | |
years.each do |year| | |
if year % 100 == 0 && year % 400 == 0 | |
leap_years.push(year) | |
elsif year % 4 == 0 && year % 100 != 0 | |
leap_years.push(year) | |
end | |
end | |
puts "Here are all the leap years: #{leap_years}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment