1

While attempting to print a fibonacci series using tuples, iPython tends to crash.

Here is the code I am trying to execute.

n = raw_input("Please enter a number: ")

a = 0
b = 1
while b < n:
    (b,a) = (a,b+a)
    print b

However, if I replace n with a number (eg. 20, 100, 1000), it runs smoothly. I also tried to run this code in Pycharm, with similar results. Pycharm ran the code, with a huge stream on numbers being generated, and a warning which read:

Too much output to process

What causes this crash?

timgeb
  • 76,762
  • 20
  • 123
  • 145
user2762934
  • 2,332
  • 10
  • 33
  • 39

2 Answers2

1

You forgot to turn the string n you get from raw_input into an integer.

Since the comparison is done by type name in this case b < n will always be True.

Use n = int(raw_input("Please enter a number: "))

timgeb
  • 76,762
  • 20
  • 123
  • 145
0

Because the return value of raw_input is str, you should try n = int(raw_input("Please enter a number: ")) instead.

BoscoTsang
  • 394
  • 1
  • 14