Fibonacci sequence inconsistency -
i've made short programme generate fibonacci sequence in length specified user. @ moment when run code , input digit 6, display sequence follows:
1 , 1,2,3,5,8,
how rid of initial spaces while string stays on 1 line? below 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 positive integer 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")
else: print("the fibonacci sequence: ") print(f1,end=",") print(f2,end=",")
this simplest solution per perspective.. seeing code seems output should rid of initial spce seek per suggetion & allow me know output
fibonacci
No comments:
Post a Comment