[Courses] [python] Lesson 1: Hello world
aka.motub at gmail.com
Wed Jun 22 18:24:16 UTC 2011
Hey, Scott, thanks a lot! I'm sending this back to the list as I think was
intended (your original was sent only to me, stupid GMail :P ).
So my revised Hello World script looks like this (also with a little "+"
fillip from Akkana :) ):
print "Hello, World!"
name = raw_input("What is your name?\n")
print "Hello,", name+"!"
with the result:
What is your name?
I know it's "just" the traditional "Hello, World!" script that all
programming courses start with, but I must admit I'm pleased as punch...
this little script does exactly what it's supposed to, and formats the
output exactly as I want it to. A rousing success, imo :) .
Onwards and upwards!
2011/6/22 Scott Newson <scott.g.newson at gmail.com>
> > So now I
> > want to know-- how do you know when the command has 'ended' ? Is it just
> > putting a hard return to the next line, as in the extended example that
> > includes user input?
> I've heard that python uses 'whitespace' to separate commands, I guess that
> this is an example of that. To have a single command over multiple lines, it
> looks like one adds a '\' character at the end of a line. ie
> >>> print "Hello \
> >>> world"
> > If so, what if I wanted to print two lines that had a
> > hard return between them? For example, if I wanted the answer to "What is
> > your name" to be printed on the next line (which would look better)? I
> > imagine there's an escape character to signify that....?
> The escape character here is '\n' ie
> >>> print "Hello \n world"
> I have also just use two separate print statements if it makes sense to me
> when programming.
More information about the Courses