working on very first exercise, it asks to make a program that does this... 1. Asks the user to enter his/her last name. 2. Asks the user to enter his/her first name. 3. Prints out the user’s first and last names in that order. After an hour this is the best I could come up with. >>> firstname=raw_input('Enter your first name') Enter your first namePaul >>> lastname=raw_input('Enter your last name') Enter your last nameGillett >>> print firstname+lastname PaulGillett I know it isn't right. Someone please give me a hint!
That is the idea. It looks like you might be typing straight into Idle. If you open a new python document, then you can write a complete program, save it, and then run it in Idle. The only thing I would change is your print statement. As it is now you are concatenating (sp?) the strings (fancy way of saying adding them together into one long string). You could alternatively use commas to print multiple variable on the same line...
Hmm... I don't understand :( I was writing it in IDLE. If I'm not supposed to write it there, where am I supposed to write it?
If you open IDLE and click File -> New Window (or his command-N on a MAC) a new window will open in which you can write out your program. Then, once you have written your program hit F5, it will prompt to save (save it as programname.py), and then run your program in the python shell. Does that make more sense?
nevermind! it works! THANKS SO MUCH :)
The strings are running together because there's no space between the prompt and the user's input. You can add a space to the end of the 'Enter your first name' string to make it prettier. Oh, the output is smushed together, too. Yes, do as seanlerner suggested and use a comma in the print statement instead of a +. Or, stick a string with a single space between the two strings (using a couple + operators and the string " ").
try print(firstname,lastname) , which gives you a space in the middle, mine is python 3.2.2 so it uses syntax that might be different from yours. Professor uses version 2.7, which has a different syntax to format a string.
v 3 uses pint in a totally different way. Also, deujasuraj, if you plan on doing this course I recommend getting v 2.7
This is what I came up with yesterday when I tried. lname = raw_input("Enter last name: ") fname = raw_input("Enter First name: ") print (fname) + " " + (lname)
okay I have this exact code written with v2.7 and I keep getting error?
cr128007: the code EricKo wrote won't work in 2.x releases. In v3 they changed the way print functions (by making it a function!) Take a look at this: http://docs.python.org/release/3.0.1/whatsnew/3.0.html#print-is-a-function
and EricKo, for this course I highly recommend using v2.x (2.7 works, the course was designed around 2.5 I believe). There are quite a few differences between 2.x and 3.
I am using 2.7.2
Can someone help me? I have reached the right code and saved it as instructed. But what I can't understand is should it run in IDLE... is there something I must do?
Join our real-time social learning platform and learn together with your friends!