Simple Problems: Caps and Commas
Bjorn Pettersen
bjorn.pettersen at comcast.net
Mon Oct 27 02:23:40 EST 2003
"Kyle E" <Kyle_E2006 at hotmail.com> wrote in
news:1067232285.558527 at news001.transaeris.com:
> I wrote a program that asks a user questions and records the answers
> and prints them out at the end. Pretty simple... but I have a few
> things that I don't like about it.
> ----------------------------------------------
> print "Do you have a P.O. Box?"
> poan = raw_input ("> ")
> if poan == "yes":
> print "What is your P.O. Box number?"
> pobox = input ("> ")
> ----------------------------------------------
> When someone answers "Yes" with cap first letter it determines that
> "yes" does not equal "Yes" what are some possible ways to resolve this
> issue?
# lower() is a string method, the in operator tests for list membership
if poan.lower() in ['yes', 'y', 'yup', 'ja']:
...
> ======================================
> Secondly I'm having a problem with listing information after all user
> input "strings" are assigned to various words.
>
> I tried this:
> -----------------------------------------------
> print "Name: ", fname, mname, lname
> print "Address: ",saddy, ",",city, ",",state, ",",zip
> -----------------------------------------------
>
> But I get extra spaces after each value:
# the % operator does 'string interpolation' and gives you more control
# over the outputstring
print 'Name: %s, %s, %s' % (fname, mname, lname)
hth,
-- bjorn
More information about the Python-list
mailing list