I have a simple piece of code that I’m not understanding where my error is coming from. The parser is barking at me with an Unexpected Indent on line 5 (the if statement). What is the problem here?
def gen_fibs():
a, b = 0, 1
while True:
a, b = b, a + b
if len(str(a)) == 1000:
return a
If you just copy+pasted your code, then you used a tab on the line with the
ifstatement. Python interprets a tab as eight spaces and not four. Don’t ever use tabs with Python1 🙂1 Or at least don’t ever use tabs and spaces mixed. It’s highly advisable to use four spaces for consistency with the rest of the Python universe.