0

Python for beginners node 36 (Sum of consecutive numbers) factorial not working

I did the math library's factorial() too ans it doesn't output proper results, is it the compiler's problem? N = input() factorial = 1 if int(N) > 1: for i in range(1, int(N)+1): factorial = factorial * i print(factorial) It outputs 10+ digits more than expected

13th Mar 2021, 3:19 AM
Coalemus
2 Respuestas
+ 5
Is that the whole code? I don't know for sure, but sum of consecutive numbers is different with factorial. Sum means to add, factorial means to multiply. Did I miss something?
13th Mar 2021, 3:52 AM
Ipang
+ 1
The adding concept went over my head and I thought of factorials hahaha, but here's the mvp that worked N = input() factorial = 1 if int(N) > 1: for i in range(1, int(N)+1): factorial = factorial + i print(factorial - 1)
13th Mar 2021, 3:58 AM
Coalemus