# Find the factorial of a number

def fact(n):
p = 1
for i in range(1, n+1):
p = p*i
return p
if name == 'main':
n = int(input('Enter an integer to find the factorial of: '))
f = fact(n)
print('Factorial of {0}: {1}'.format(n, f))

이걸 factorial.py로저장하고 새 idle에서 from factorial import fact 입력을했는데
Traceback (most recent call last):
File ", line 1, in
import factorial
File
C:\Users\이썬\factorial.py", line 1
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
^
SyntaxError: invalid syntax

이런 에러가뜹니다 뭐가 잘못된걸까요 ...

##### 1 개의 답변

질문 내용이 이해가 잘 안됩니다.

아래는 위 내용을 유추하여 해본 결과 입니다.

``````# fatorial.py
def fact(n):
p = 1
for i in range(1, n+1):
p = p*i
return p

# idle.py
from factorial import fact

if __name__ == '__main__':
n = int(input('Enter an integer to find the factorial of: '))
f = fact(n)
print('Factorial of {0}: {1}'.format(n, f))
``````

실행 결과 :

``````python idle.py

Enter an integer to find the factorial of: 4
Factorial of 4: 24
``````