Created
September 18, 2016 20:05
-
-
Save rampavan90/b71bb349d41601f3e3211fc11503dc9c to your computer and use it in GitHub Desktop.
Home work Project in Ruby(Udemy Course)
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
#Hash dictionary to store our cities and corresponding area codes | |
#Please suggest me better solutions and I want to learn from you. | |
$dial_book = { | |
"Hyderabad"=>"45", | |
"Pune"=>"56", | |
"Mumbai"=>"32", | |
"Chennai"=>"45", | |
"Delhi"=>"67", | |
"Kolkata"=>"89", | |
"Bengaluru"=>"12", | |
"Kochi"=>"1", | |
"Amaravathi"=>"22", | |
"Gangtok"=>"213" | |
} | |
#Method to show the city names as a list for the User | |
def showcitynames | |
puts "These are the City Names" | |
$dial_book.each do |name| | |
puts "#{name}" | |
end | |
getareacode | |
end | |
#method to get areacode,dial_book and the cityname | |
def getareacode | |
puts "Please select a City Name from the above list" | |
cityname = gets.chomp | |
code = $dial_book.select{|k,v| k==cityname} | |
puts "The Area Code is #{code[cityname]}" | |
end | |
#loop functionality down called definition showcitynames | |
loop do | |
puts "Do you want to lookup a cityname?(Y/N)" | |
answer = gets.chomp | |
if answer != "Y" | |
break | |
else | |
showcitynames | |
end | |
end | |
#End of Area Code dictionary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello guys,Please do comment on my code and Please do advice me on better solutions.