My first script (so go easy on me!)

Erik Max Francis max at alcyone.com
Tue Jan 16 12:40:33 EST 2001


Robert L Hicks wrote:

> Is this ok?

It works, though I'd do a safer comparison with actual strings, like:

    if answer == 'yes':
        print r
    elif answer == 'no':
        print w
    else:
        print n

Note what happens in your program if you answer `nope' instead of `no'. 
You could also just key off the first character:

    if answer[0] == 'y':
        print r
    elif answer[0] == 'n':
        print w
    ...

You also don't particularly gain anything in this tiny example by saving
the strings you want to print off into variables that you use later,
although in what you're planning to do, it might make sense eventually;
it's certainly not wrong.

> My question is when the print statement is run do I need
> to do a
> linefeed so the terminal accepts what was printed? Or does the fact
> that
> python send the print to the terminal cause the terminal to execute
> it?

An unadorned print statement implicitly has a newline stuck to the end
of it, and comma-separated items are printed with intervening spaces. 
So you can write things like:

    i = 10
    print "The number of items left is", i

To suppress the trailing newline, end with a comma (but it will end with
a trailing space):

    print "Do you want to quit?",

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ I am the king of sorrow
\__/ Sade
    Official Buh rules / http://www.alcyone.com/max/projects/cards/buh/
 The official rules to the betting card game, Buh.



More information about the Python-list mailing list