I'd do it like this And there's probably an even quicker way, if
you really sat down and thought about it.
n = int(raw_input("Number: "))
x = n-1
while x 1:
n *=x
x -=1
print n
The reason why it isn't working is because of
"
while x 1:
x -= 1
"
When your program hits this point it stays in the while loop,
subtracting 1 from x each time, but not multiplying anything anymore,
until it hits break. So your program does this.
Number: 4
n = 5
x = 4
t = 20
x = 3
x = 2
x = 1
BREAK.
Cheers!
15/08/05, Nathan Pinno <falcon3166 (AT) hotmail (DOT) comwrote:
The following code is supposed to take in a number, and print number!:
n = int(raw_input("Number: "))
x = n-1
while 1:
t = n*x
while x 1:
x -= 1
else:
break
print t
Why isn't it working, and how can I make it print out the correct output?
Thanks in advance,
Nathan
Early to bed,
Early to rise,
Makes a man healthy, wealthy, and wise.
Franklin
Tutor maillist - Tutor (AT) python (DOT) org
>
>
>
>
Tutor maillist - Tutor (AT) python (DOT) org