0

I am currently learning Python and decided to make this program that does a Fibonacci Sequence so i could subsequently import it on a new program, however somethings wrong with it and I am not sure what it is.

print(input('Please state the value of n: ' ))

a, b = 0, 1

print(a)

while b < n:

    print(b)

    a, b= b, a+b

I wanted to be able to import the input command but apparently somethings wrong with the code. Any help?

I tried adding int(input('Please state the value of n')) but it still does not work for some reason.

Tyler Tian
  • 597
  • 1
  • 6
  • 22

2 Answers2

1

you forgot to define 'n' as variable.

n = (input('Please state the value of n: ' ))

a, b = 0, 1

print(a)

while b < n:

    print(b)

    a, b= b, a+b
Coleone
  • 63
  • 2
  • 12
  • I am so dumb, You are right I changed print(input("Please state the vlaue of n: ")) to n =int(input('please state the value of n: ')) and it worked. Thank you so much! – nooneofinterest I Oct 07 '20 at 04:21
  • still need to wrap the input call with `int`. As it stands, `n` is a string. – flakes Oct 07 '20 at 04:23
0

you have to assign the input to n and cast it to integer , that will fix your problem .

n = int(input('Please state the value of n: ' ))

Hope it helps <3

Hosseinreza
  • 561
  • 7
  • 18