anonymous
  • anonymous
I have written some code for problem set 0. print raw_input('what is your first name?') firstname = raw_input('what is your first name?') print raw_input('what is your last name?') lastname = raw_input('what is your last name?') print ('your name is ' + firstname + lastname) When i run the program why does it ask for my first name twice and my last name twice before displaying the result? >>> what is your first name?Ben Ben what is your first name?Ben what is your last name?Deed Deed what is your last name?Deed your name is BenDeed >>> Also how do i add a space?
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
i will check it later i will give u solution
anonymous
  • anonymous
firstname = raw_input('what is your first name?') actually prints "what is your first name" So, you have two options -- Either have a separate line for the print but DON'T print it again in the raw_input statement (notice that there's a print statement that just prints, then the next line gets raw input and assigns it to firstname): >>> print 'what is your first name?' >>> firstname = raw_input() Or, you can put the text for the print statement in between the parentheses for the raw input and do it all on one line >>> firstname = raw_input('what is your first name?') Your's is printing it all out twice because you're telling it to print out twice (once in the print statement, and then again by sending the string as a parameter to raw_input when you assign the variable).
anonymous
  • anonymous
for the space problem try this print ('your name is ' + str(firstname) + ' ' + str(lastname)) you will get a space in between,, i guess you can remove the str also

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
Ok great, thanks for the help. so i guess all i need is: firstname = raw_input('what is your first name?') lastname = raw_input('what is your last name?') print ('your name is ' + firstname + lastname) it has confused me slightly as the raw_input is printing the string even though i never instructed it to.
anonymous
  • anonymous
raw_input() asks the user for a string of data (ended with a newline), and simply returns the string - http://en.wikibooks.org/wiki/Python_Programming/Input_and_output So the raw_input function has kind of a print function built in to it.
anonymous
  • anonymous
@Bwaters Yes, yes it does :) Also, like @Aleem said, you might want to put a space in between the first and last names in your final print statement (just so they don't run together). to do this you just put a plus sign, two single quotes with a space between them, and then another plus sign + ' ' + in between first and last name in your print statement, thusly: print ('your name is ' + firstname + ' ' + lastname) That way you get: your first name is John Smith instead of: your first name is JohnSmith
lopus
  • lopus
http://dpaste.com/788502/ execute written problem0()
lopus
  • lopus
print ('your name is ' + firstname +' '+ lastname)

Looking for something else?

Not the answer you are looking for? Search for more explanations.