Skip to content

Instantly share code, notes, and snippets.

@heavymetta
Created September 3, 2015 15:22
Show Gist options
  • Save heavymetta/817657f9c544566591ab to your computer and use it in GitHub Desktop.
Save heavymetta/817657f9c544566591ab to your computer and use it in GitHub Desktop.
State & City
states = {
OR: 'Oregon',
FL: 'Florida',
TX: 'Texas',
NY: 'New York'
}
# task1 /////
states[:OG] = 'Oregon'
states[:COLO] = 'Colorado'
# task2 /////
@cities = {
OR: 'Portland',
FL: 'Tampa',
TX: 'Dallas',
NY: 'New York'
}
#task3 /////
def describe_state(state)
@cities[state]
end
puts describe_state(:NY)
#task 4 /////
@taxes = {OG: 9, COLO: 8}
#task 5 /////
def calculate_tax(price_of_item, state)
tax = @taxes[state] / 100.to_f
tax_paid = price_of_item * tax
tax_paid.round(2)
end
puts calculate_tax(50, :OG)
puts calculate_tax(60, :COLO)
#task 6 /////
def find_state_for_city(seeking_city)
@cities.keys.each do |state|
if @cities[state] == seeking_city
puts "#{seeking_city} is located in #{state} state"
end
end
end
find_state_for_city('Portland')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment