Are my answers to Ps0 correct?
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') >>>
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?
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
do you mind if i jump in?
thanks - i'm loving the MIT course and it's good to meet people here
great! we think so too =). the community is very helpful. it's just nice to not have to learn such challenging material alone.
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 :-)
I'm right here actually :)
ah there he is
that was weeirddd but cool
lol I know what you mean.
i'm going to take a look around...
sweet. nice meeting you.
Hi to every one. What is recommended book to learn python along with the course?
how do you print in the next line?
Hm. What do you mean by the next line?
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)
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.
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.
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
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?
Hm. Can you give us the full error message? It should have more details which will help in determining what is going on.
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
And what are the contents of the file?
>>> 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
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?
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
@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.
@shadowfiend, thanks! =)
No problem, glad to help!
If you like to be grammatically correct, then for the last line, do the following: print "Your name is " + firstname + ' ' + lastname :)