Roman Sionis
Roman Sionis

Reputation: 11

Fibonacci sequence inconsistency

I've made a short program to generate the fibonacci sequence in a length specified by the user. At the moment when I run the code and input a digit like 6, it will display the sequence as follows:

1 , 1,2,3,5,8,

How do i get rid of the initial spaces while the string stays on one line? below is my code

#user intiger input
print("\n")
f = int(input("Enter length of sequence: "))
print("\n")


f1 = 1
f2 = 1
multiply = 2


if f <=0:
   print("Enter a positive integer for the length: ")


elif f == 1:
   print("The Fibonacci sequence: ")
   print("\n")
   print(f1,end=',')

else:
   print("The Fibonacci sequence: ")
   print(f1,",",f2,end=",")
   while multiply < f:
       f3 = f1 + f2
       print(f3,end=",")

       f1 = f2 
       f2 = f3 
       multiply += 1

print("\n")

Upvotes: 1

Views: 67

Answers (1)

Nishant
Nishant

Reputation: 136

else:
print("The Fibonacci sequence: ")
print(f1,end=",")
print(f2,end=",")

This is the simplest solution as per my perspective.. but by seeing your code its seems like output should be rid of initial spce however try as per suggetion & let me know output

Upvotes: 1

Related Questions