Create a module series.py containing functions to determine Fibonacci series and Exponential series. Import the module created to make it accessible, and Call the functions of that module with module name . Demonstrate the access of functions in the module created.
# series.py
def Fibonacci(n):
if n == 0:
return 0
f0 = 0
f = 1
for i in range(1, n):
f, f0 = f+f0, f
return f
def Exponential(n, x=1):
s = 1
a = 1
for i in range(1,n+1):
a *= x/i
s += a
return s
import series
def main():
n = int(input("Enter a positive integer: "))
if n < 0:
print('Not positive number!')
exit()
f = series.Fibonacci(n)
print(f'{n}-th Fibonacci number is {f}')
x = float(input('Enter a number: '))
y = series.Exponential(n, x)
print(f'Exponetial({n}, {x}) = {y}')
if __name__ == '__main__':
main()
Comments
Leave a comment