Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

bwaters Group Title

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?

  • one year ago
  • one year ago

  • This Question is Open
  1. msamido Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    i will check it later i will give u solution

    • one year ago
  2. RoamingBlue Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    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).

    • one year ago
  3. Aleem Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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

    • one year ago
  4. bwaters Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • one year ago
  5. bwaters Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

    • one year ago
  6. RoamingBlue Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    @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

    • one year ago
  7. lopus Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    http://dpaste.com/788502/ execute written problem0()

    • one year ago
  8. lopus Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    print ('your name is ' + firstname +' '+ lastname)

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.