I'm new to python and I'm just testing importing a function from one module into another module using from module_name import function
. However, when I import the function it also imports and executes a for loop that is not a part of the function but is part of the module.
Module 1:
from Fibonacci import fibonacci
fibonacci(10)
Module 2:
def fibonacci(Number):
for i in range(1,Number+1):
if i == 1:
sumCount = 0
First = 0
elif i ==2:
Second = 1
sumCount = 1
else:
sumCount = First + Second
First = Second
Second = sumCount
print(sumCount)
for F in range(1,10):
fibonacci(F)
When I import the function fibonacci, the for loop is executed. Why is this and how can I stop this?