Here's the code I'm having trouble shortening. I am currently a beginner in Python 3.x.
from os import system
def fibonacci(terms):
count = 0
x = 0
y = 1
z = x + y
if terms <= 0:
print("Enter a positive integer.")
elif terms == 1:
print("Fibonacci sequence in " + str(terms) + " terms.")
print(x)
else:
print("Printing " + str(terms) + " terms.")
while count < terms:
print(x)
z = x + y
x = y
y = z
count += 1
while True:
user_input = int(input("How many terms? "))
fibonacci(user_input)
loop = input("Again? (Y/n) ")
if loop == "Y" or loop == "":
system("cls")
else:
exit()
I would appreciate if there will be someone who will be able to make this as efficient as possible.