From: Justin Collins Date: 2010-02-11T15:09:41+09:00 Subject: Re: Need help with Code (Input Functionality) Seebs wrote: > On 2010-02-11, Michael Brodeur wrote: > >> When I run the following code: >> >> puts 'What is your name?' >> name = gets >> puts 'What is your city?' >> city = gets >> puts 'What is your favorite color?' >> color = gets >> puts "Your name is #{name}.", "You live in #{city}.", "Your favorite >> color is #{color}." >> >> --------------------------------------- >> >> The result I get in terminal is: >> >> --------------------------------------- >> >> Your name is (name input) >> > > Hmm, that's odd. My quick trial produces the "expected" output. > > I would guess that, for reasons too subtle for me to guess, you're ending > up with > (puts "Your name is #{name}."), ("You live in #{city.}"), ("Your favorite > color is #{color}.") > > rather than a single expression (a puts with three arguments), but I can't > imagine why. > > -s > Really? Because you shouldn't be (unless we have a different idea of what the expected output should be.) The issue is that gets will return the EOL character, which is what is causing Michael's output to have a return prior to the period in each sentence. In other words, you put in "Bob" as your name, followed by , which causes the program to received "Bob\n" as the input. As P.Raveendran points out, you probably want to remove that, by using chomp or strip. -Justin