python - How to get a number as user input and use in while loop to print Fibonacci number -


i using following print fibonacci numbers.

a, b = 0, 1 while b < 200:        print b,        a, b = b, a+b 

in above program, want take number 200 user input. tried following:

a, b = 0, 1  while b < (int(raw_input("enter number : "))):        print b,        a, b = b, a+b 

if run above script, asks input 2 times , prints nothing shown below:

c:\users\test\desktop>python fib.py enter number : 200 1 enter number : 1  c:\users\test\desktop>   

how fix this?

if raw_input in condition of while, prompt user input every single time go through loop. if want prompt user once, put before loop.

a, b = 0, 1  limit = int(raw_input("enter number : ")) while b < limit:        print b,        a, b = b, a+b 

result:

enter number : 200 1 1 2 3 5 8 13 21 34 55 89 144 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -