Thanks guys, I got it working for what I need at the moment with <br><br><div style="margin-left: 40px;">#Factorial finder<br><br>factorialNum = 1L<br>print "Factorial finder"<br>number = int(input("Please enter a non-negative integer: "))<br>
<br>for number in range(1, number):<br> factorialNum = (factorialNum * (number + 1))<br> print factorialNum<br><br>print "Factorial:", factorialNum<br><br></div>On this mailing list, is there a general rule about how to place code? I.e. ident, italics, quotes???<br>
<br><div class="gmail_quote">2009/6/12 ayyaz <span dir="ltr"><<a href="mailto:ayyaz84@gmail.com">ayyaz84@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Eddie wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">
I'm trying to write a simple factorial program and am unsure at what is wrong with it. Why Can't I go *factorial = factorial * number* where factorial and number are both integers?<br>
<br>
#Factorial program<br>
<br>
print "Factorial finder"<br>
number = input("Please enter a non-negative integer: "<br>
for number in range(number, 1)<br>
factorial = (factorial * number)<br>
<br>
print "Factorial:", factorial<br>
Thanks Eddie<br>
<br>
<br></div></div>
------------------------------------------------------------------------<div class="im"><br>
<br>
_______________________________________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org" target="_blank">Tutor@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</div></blockquote>
Hello Eddie,<br>
<br>
You never initialized the variable factorial. So the line<br>
"factorial = (factorial * number)" will crash your program since<br>
the program doesn't know what the variable factorial is.<br>
<br>
I would modify your code as follows:<br>
<br>
factorial = int(raw_input("\nPlease enter a non-negative integer: "))<br>
<br>
for i in range(1,factorial):<br>
factorial *= i<br>
<br>
print "Factorial:", factorial<br>
<br>
raw_input("\nPress enter to exit")<br>
<br>
<br>
I hope this helps.<br><font color="#888888">
--ayyaz</font><div><div></div><div class="h5"><br>
<br>
_______________________________________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org" target="_blank">Tutor@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</div></div></blockquote></div><br>