CityId Mini Project

City Info

Is a hash with a list with the names of cities & their zip codes.

city_info = {"lilburn" => "30047","norcross" => "30003","lawrenceville" => "30044","dacula" => "30019","alpharetta" => "30009","decatur" => "30030","loganville" => "30052","marietta" => "30060","roswell" => "30076","auburn" => "30011"}
def get_city_name(somecity)end
def get_zip_code(somecity, key)end
loop do
end
loop doputs "Do you want to lookup an area code based on a city name?(Y/N)"answer = gets.chomp.downcasebreak if answer != "y"puts "Which city  do you want to lookup the zip code for?"
puts get_city_name(city_info)
puts "Enter your choice"
prompt = gets.chomp
if city_info.include?(prompt)puts "The zip code for #{prompt} is #{get_zip_code(city_info, prompt)}"elseputs "you entered an invalid city name"endend
city_info = {"lilburn" => "30047","norcross" => "30003","lawrenceville" => "30044","dacula" => "30019","alpharetta" => "30009","decatur" => "30030","loganville" => "30052","marietta" => "30060","roswell" => "30076","auburn" => "30011"}#create a method to get city_by_namedef get_city_name(somecity) somecity.keys
#.keys method lists out all the keys
end
#create a method to get the zip and return a city associated with itdef get_zip_code(somecity, key)somecity[key] #returning the value hash passed in and key value.end#use execution flow#infinite loop-no buenoloop doputs "Do you want to lookup an area code based on a city name?(Y/N)"answer = gets.chomp.downcasebreak if answer != "y"puts "Which city do you want to lookup the zip code for?"puts get_city_name(city_info)#now enter a selection and get inputerputs "Enter your choice"prompt = gets.chomp#chance User enters invalid city, let user know if/elseif city_info.include?(prompt)puts "The zip code for #{prompt} is #{get_zip_code(city_info, prompt)}"elseputs "you entered an invalid city name"endend

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store