Need help with programming in python for class (beginner level)

Tim Chase python.list at tim.thechases.com
Fri Nov 29 19:53:00 EST 2013


On 2013-11-29 16:31, farhanken at gmail.com wrote:
> It's for a school assignment.

Thanks for the honesty--you'll get far more helpful & useful replies
because of that. :-)

> put them into a variable I called "number" but it seems to glitch
> out that variable is in any command other than "print number".
> Like, if I try to write:
> 
> print "<p>your total number was:" number "</p>" 
> 
> It just doesn't work. 

You're so close.  Python doesn't let you directly combine strings and
numbers like that, especially without any operator.  However it does
offer several ways to combine strings:

  print "convert to string and use " + str(number) + " a '+' operator"
  print "use %s classic C-style formatting" % number
  print "use new {} formatting style".format(number)

-tkc






More information about the Python-list mailing list