Part 1: Asking Questions3:10 with Jason Seifer
Now that we're familiar with loops and iteration, let's practice our knowledge by writing a simple contact list program.
Here is the code we write in this portion of the video.
First, we set up a contact list array:
contact_list = 
Next, we define the
ask method. We're going to be asking the user for input quite a bit so the
ask method will repeat the logic for us.
def ask(question, kind="string")
print question + " "
answer = gets.chomp
answer = answer.to_i if kind == "number"
ask method takes two arguments and defaults to having the
kind of answer be a string. This will let us return numeric values if we want.
Finally, we test the
answer = ask("What is your name?")
You need to sign up for Treehouse in order to download course files.Sign up