1

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
asked Nov 8, 2017 at 12:13
1
  • 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. Commented Nov 8, 2017 at 14:02

1 Answer 1

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.

answered Nov 8, 2017 at 14:17
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.