【发布时间】:2017-07-02 16:37:41
【问题描述】:
area_dictionary = {
"Alabama" => "205",
"Alaska" => "907",
"American Samoa" =>"684",
"Arizona" => "480",
"Arkansas" => "479",
"California" => "209",
"Colorado" => "303",
"Connecticut" => "203",
"Delaware" => "302",
"Florida" => "239",
"Georgia" => "229",
"Guam" => "671",
"Hawaii" => "808"
}
def get_city_name(hash,key)
hash.each{|k,v|puts k if v==key}
end
puts"Please enter the code for which you want to find the city?"
code = gets.chomp
if area_dictionary.include?(code)#getting trouble from here
puts "The city for #{code}is#{get_city_name(area_dictionary,code)}"
end
【问题讨论】:
-
你试过什么?你搜索过这个吗?我想这方面的信息应该无处不在。
-
我推荐阅读the docs。
-
def get_city_name(hash,key) hash.each{|k,v|puts k if v==key} end puts "请输入您要查找城市的代码?" code = gets.chomp if area_dictionary.include?(code) puts "The city for #{code} is #{get_city_name(area_dictionary,code)}"
-
请编辑您的问题并在此处添加代码。
标签: ruby