Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 36 Online
OpenStudy (anonymous):

Are my answers to Ps0 correct?

OpenStudy (anonymous):

Python 2.7 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> lastname = raw_input ("What is your last name? ") What is your last name? Doe >>> firstname = raw_input ("What is your first name? ") What is your first name? Noby >>> print ("Your name is ", firstname + lastname) ('Your name is ', 'NobyDoe') >>>

OpenStudy (anonymous):

I was just wondering if my answers were correct or should I have done them in a "command line" style where the user is asked along the way for there input?

OpenStudy (chris):

Right - this is how I coded it when for the command line. print "Enter your last name:" answer1 = raw_input("** " ) print "Enter your first name:" answer2 = raw_input("** ") print answer2, answer1

OpenStudy (sandra):

do you mind if i jump in?

OpenStudy (anonymous):

hi chris

OpenStudy (chris):

hello!

OpenStudy (chris):

welcome

OpenStudy (anonymous):

thanks - i'm loving the MIT course and it's good to meet people here

OpenStudy (chris):

great! we think so too =). the community is very helpful. it's just nice to not have to learn such challenging material alone.

OpenStudy (anonymous):

i was looking for shadowfiend, it says he is in one of the study conversation but i cant seem to see him. maybe he's resting :-)

OpenStudy (shadowfiend):

I'm right here actually :)

OpenStudy (anonymous):

ah there he is

OpenStudy (chris):

haha lurker!

OpenStudy (anonymous):

that was weeirddd but cool

OpenStudy (chris):

lol I know what you mean.

OpenStudy (anonymous):

i'm going to take a look around...

OpenStudy (chris):

sweet. nice meeting you.

OpenStudy (anonymous):

Hi to every one. What is recommended book to learn python along with the course?

OpenStudy (anonymous):

how do you print in the next line?

OpenStudy (shadowfiend):

Hm. What do you mean by the next line?

OpenStudy (tim):

HI Ja!

OpenStudy (anonymous):

I'd also like to contribute in this topic if you folks don't mind. I wanted to emulate something similar to the example on the pdf file. I wanted to get these results: Enter your last name: Doe Enter your first name: Jane Your name is: Jane Doe I wrote down the following for it: lastname = raw_input('Enter your last name: '); firstname = raw_input('Enter your first name: '); print ('Your name is: ' + firstname + ' ' + lastname)

OpenStudy (anonymous):

slight variation to ja9's work makes it more user friedly What is your last name? Doe What is your first name? John Hello John Doe print "What is your last name?"; lastname = raw_input(); print "What is your first name?"; firstname = raw_input(); print "Hello", firstname, lastname; having the print before the raw_input makes it jump to the next line. the raw_input() means the line where they type there is nothing on it.

OpenStudy (shadowfiend):

Nice. Also, @commando1200, keep in mind that you don't need semicolons on the end in Python -- you can just change lines. You only need semicolons if you're going to put two distinct statements on the same line, which is generally frowned upon in Python anyway.

OpenStudy (anonymous):

This is what I did. I basically looked at the example in the problem set and just did that: last = raw_input("What is your last name?\n") first = raw_input("What is your fist name?\n") print first print last

OpenStudy (anonymous):

I'm having trouble running my program. I wrote the code in IDLE and when I enter the last line (e.g. >>>print 'Hello', firstname, lastname) I get the correct response. But when I try to open the program in Python Launcher, i get an error saying invalid syntax. Can anyone offer any advice?

OpenStudy (shadowfiend):

Hm. Can you give us the full error message? It should have more details which will help in determining what is going on.

OpenStudy (anonymous):

kevins-macbook-pro-15:~ kevin$ cd '/Users/kevin/Desktop/' && '/usr/local/bin/pythonw' '/Users/kevin/Desktop/ps0try.py' && echo Exit status: $? && exit 1 File "/Users/kevin/Desktop/ps0try.py", line 1 Python 2.7.1 (r271:86882M, Nov 30 2010, 09:39:13) ^ SyntaxError: invalid syntax

OpenStudy (shadowfiend):

And what are the contents of the file?

OpenStudy (anonymous):

>>> print 'What is your last name? ' What is your last name? >>> lastname=raw_input() >>> print 'What is your first name? ' What is your first name? >>> firstname=raw_input() >>> print 'Hello', firstname, lastname Hello

OpenStudy (anonymous):

Ah ha! I figured it out. The >>> symbols shouldn't be in the saved file. So the new question is how do I save a file in IDLE so that the text file doesn't contain the greater than signs?

OpenStudy (anonymous):

Hi guys, I just started on this class and I'm a bit overwhelmed by it. Anyway, can I just chip in and ask if my answer to PS0 is right? Or is the some other way I should write it in? answer1 = raw_input ('What is your last name?') answer2 = raw_input ('What is your first name?') print answer2, answer1

OpenStudy (shadowfiend):

@k1e4v -- I believe IDLE has a File->New File or some such option that will let you open a new file in an editor. Then there will be a menu option that will let you run that file in the execution window where you've been typing until now. @alexisthetiny -- Looks good to me! Might want to put a space after the question mark on the raw_inputs so that the user isn't typing immediately next to the question mark, though.

OpenStudy (anonymous):

@shadowfiend, thanks! =)

OpenStudy (abby):

OpenStudy (shadowfiend):

No problem, glad to help!

OpenStudy (anonymous):

If you like to be grammatically correct, then for the last line, do the following: print "Your name is " + firstname + ' ' + lastname :)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!