let's suppose that there's a two python file
file1
from math import factorial
def factorial(n):
return factorial(n)
file2
from file1 import factorial
a = input("n : ")
print (factorial(a))
Question:
I want to give the value of 'a' from file2 to file1, but I don't know how to do it ?
Kroltan
5,1565 gold badges40 silver badges64 bronze badges
-
Instead of importing factorial from file1 to file2, import 'a' from file2 to file1. You can directly take input in file1. What is the reason to take input in a separate file and then import it? you can take input directly in file1.caped114– caped1142017年11月08日 14:02:50 +00:00Commented Nov 8, 2017 at 14:02
1 Answer 1
file1
import math
def fact(n):
return math.factorial(n)
file2
from file1 import fact
a = int(input("n : "))
print (fact(a))
First of all import math module in file to calculate the factorial defined in math module and then import fact function from file1 to file2
now take some input by input() the number but you have to convert it to integer.
Sign up to request clarification or add additional context in comments.
Comments
lang-py