I'm a complete newbie to Python, but trying to write a simple program here and cannot figure out why my first "if" statement is not executing (from what I can tell).
I have the following:
fibo=[1,1]
num = int(input('Length of Fibonacci Sequence:'))
iterate = num - 2
for i in range (iterate):
if num < 2 :
print ('Length must be > 2')
else:
fibo.append(fibo[-1]+fibo[-2])
print ('The Fibonacci Sequence for the first', num, 'integers is:')
print (fibo)
It works exactly like I would hope for any input above 2. If I enter anything below 2, I would expect it to print "Length must be >2" but instead get no output at all.
I would appreciate any help! Thank you!
Aucun commentaire:
Enregistrer un commentaire