Need help with programming in python for class (beginner level)
Eduardo A. Bustamante López
dualbus at gmail.com
Sat Nov 30 01:45:44 CET 2013
On Fri, Nov 29, 2013 at 04:31:21PM -0800, farhanken at gmail.com wrote:
> It's for a school assignment. Basically, I need to roll 5 dies with 6 sides each. So basically, 6 random numbers. That part is easy. Then I need to add it up. Ok, done that. However, I also need to say something along the lines of "your total number was X". That's what I'm having trouble with. I added the dice rolls together and 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.
That would be: print "<p>your total number was" + str(number) + "</p>"
Notice two differences:
- Used the + operator to concatenate two strings: "foo" + "bar" == "foobar"
- Converted the number from integer to string, you can't do: <int> +
<str> directly, you have to either int(<str>) + <int> if you want to do
an integer addition, or: str(<int>) + <str>, if you want string
You didn't use an operator, and «"string" variable "string"» is not
Eduardo Alan Bustamante López
More information about the Python-list