Created
March 12, 2015 21:24
-
-
Save phlipper/715f9784e1443a3aa2e8 to your computer and use it in GitHub Desktop.
TECH601-00 Day 3 Exercise - Country Data
This file contains hidden or 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
# Angola: | |
# id: AGO | |
# name: Angola | |
# population: 21,471,618 | |
# capital: Luanda | |
# latitude: -8.81155 | |
# longitude: 13.242 | |
# income level: Upper Middle | |
# high income?: false | |
country_id = "AGO" | |
country_name = "Angola" | |
country_population = 21_471_618 | |
country_capital = "Luanda" | |
country_latitude = -8.81155 | |
country_longitude = 13.242 | |
country_income_level = "Upper Middle" | |
country_high_income = false | |
puts "The population of #{country_name} is #{country_population}" | |
# The capital of _ is _ | |
# output the string "high income" if the income is high | |
# puts "High Income" if country_high_income == true | |
if country_income_level == "High" | |
puts "High Income" | |
else | |
puts "NOT High Income" | |
end | |
# output the country population if it is over 20 million | |
if country_population > 20_000_000 | |
puts country_population | |
else | |
puts "There are less than 20 million people" | |
end | |
# output "high population" if over 20 million, | |
# output "medium population" if between 10 and 20 million, | |
# output "low population" if below 10 million | |
country_population = 20_000_000 | |
if country_population > 20_000_000 | |
puts "high population" | |
end | |
if country_population >= 10_000_000 && country_population <= 20_000_000 | |
puts "medium population" | |
end | |
if country_population < 10_000_000 | |
puts "low population" | |
end | |
# compact view - happy path for conditionals | |
greater_than_20_million = (country_population > 20_000_000) | |
high_population = greater_than_20_million | |
medium_population = ((country_population >= 10_000_000) && (country_population <= 20_000_000)) | |
low_population = country_population < 10_000_000 && country_population >= 1 | |
if high_population | |
puts "high population" | |
elsif medium_population | |
puts "medium population" | |
elsif low_population | |
puts "low population" | |
else | |
"No population" | |
end | |
case | |
when high_population | |
puts "high population" | |
when medium_population | |
puts "medium population" | |
when low_population | |
puts "low population" | |
else | |
"No population" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment