Factorial number python

Closed
jersde Posts 1 Registration date Friday August 2, 2019 Status Member Last seen August 2, 2019 - Aug 2, 2019 at 07:31 PM
 Lameidiot5 - Jan 3, 2020 at 10:27 AM
Hello,

hi don't understand why this code doesn't give me the factorial number.

somma = 0
i = 1
num = getInteger("Inserisci un numero e ti dirò il fattoriale: ")

if num == 1:
print("Il fattoriale è 1 ")
else:
while i < num:
somma = i * num
print("Il risultato è: ", somma)
Related:

2 responses

kurhanskakr Posts 4 Registration date Monday December 23, 2019 Status Member Last seen January 14, 2020
Jan 3, 2020 at 05:25 AM
Why do you not reduce 'num' in the "while" cycle?
0
Just declare somma do not initialize it as zero. "I" is always one. You have a while statement that checks against a static variable. Get rid of the while and calculate it directly as previously stated. If "I" was an array, such as 1,3,5,7,9, then a while would be applicable, but it is not an array, it is static.
0