Thanks guys, I got it working for what I need at the moment with

#Factorial finder

factorialNum = 1L
print "Factorial finder"
number = int(input("Please enter a non-negative integer: "))

for number in range(1, number):
  factorialNum = (factorialNum * (number + 1))
  print factorialNum

print "Factorial:", factorialNum

On this mailing list, is there a general rule about how to place code? I.e.
ident, italics, quotes???

2009/6/12 ayyaz <[email protected]>

> Eddie wrote:
>
>> 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?
>>
>> #Factorial program
>>
>> print "Factorial finder"
>> number = input("Please enter a non-negative integer: "
>>    for number in range(number, 1)
>>    factorial = (factorial * number)
>>
>> print "Factorial:", factorial
>>      Thanks Eddie
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Tutor maillist  -  [email protected]
>> http://mail.python.org/mailman/listinfo/tutor
>>
> Hello Eddie,
>
> You never initialized the variable factorial. So the line
> "factorial = (factorial * number)" will crash your program since
> the program doesn't know what the variable factorial is.
>
> I would modify your code as follows:
>
> factorial  = int(raw_input("\nPlease enter a non-negative integer: "))
>
> for i in range(1,factorial):
>    factorial *= i
>
> print "Factorial:", factorial
>
> raw_input("\nPress enter to exit")
>
>
> I hope this helps.
> --ayyaz
>
>
> _______________________________________________
> Tutor maillist  -  [email protected]
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to