# fibo.py
def fib_series(n):
"""Prints the Fibonacci series up to n."""
a, b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a + b
print() # For a new line after the series
def fib_nth(n):
"""Returns the nth Fibonacci number."""
if n <= 0:
return 0
elif n == 1:
return 1
else:
a, b = 0, 1
for _ in range(2, n + 1):
a, b = b, a + b
return a
# main_script.py
import fibo
# Get user input for the limit of the Fibonacci series
limit = int(input("Enter a number to print Fibonacci series up to: "))
print(f"Fibonacci series up to {limit}:")
fibo.fib_series(limit)
# Get user input for the nth Fibonacci number
nth_term = int(input("Enter the position (n) to find the nth Fibonacci number: "))
result = fibo.fib_nth(nth_term)
print(f"The {nth_term}th Fibonacci number is: {result}")
python main_script.py
కామెంట్లు లేవు:
కామెంట్ను పోస్ట్ చేయండి