+ 1

How to calculate factorial in Python 3.6.2?

I would like import 'math' but I can only import 'cmath'. And there isnot gamma function or factorial. I donot want to work with complex numbers, is there any way how to import 'math' instead of 'cmath'?

26th Jul 2017, 7:57 AM
Adéla Krylová
Adéla Krylová - avatar
8 ответов
+ 10
In sololearn playground fortunately it is working: import math n = int(input("Type in the number: ")); f = math.factorial(n); print (f);
14th Sep 2017, 9:42 AM
JaMi
JaMi - avatar
+ 3
It should be possible to import math in python 3.6.2 I had extra a look in the docs. Here https://docs.python.org/3.6/library/math.html Which error occurs when you try to import math?
26th Jul 2017, 8:59 AM
Amarie
+ 3
okay. this is really strange. Sorry, but I have no idea why it doesn't work. :( maybe you install a little older version, 3.5 or so.
26th Jul 2017, 9:09 AM
Amarie
+ 3
try this: help ('modules') and look if math is listed
26th Jul 2017, 9:24 AM
Amarie
+ 2
Thanks for your help.
26th Jul 2017, 9:26 AM
Adéla Krylová
Adéla Krylová - avatar
+ 1
'No module named math' I can import only cmath :(
26th Jul 2017, 9:03 AM
Adéla Krylová
Adéla Krylová - avatar
+ 1
n = int(input("!n=")) def factorial(n): fact = 1 for i in range(n): fact = fact*(i+1) print (fact) factorial(n)
18th Jun 2018, 6:46 AM
kiril Giliuk
kiril Giliuk - avatar
0
It also work on PC, but it say that it is mistake, and write it red, but now it works. I do not know why...
17th Nov 2017, 9:42 AM
Adéla Krylová
Adéla Krylová - avatar