Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it?

Ian Kelly ian.g.kelly at gmail.com
Thu Sep 19 15:01:02 EDT 2013


Syntactically, it looks fine.  I would guess the problem is with
whatever editor you are using.  Or as John noted, it could be caused
by the code above it.

I do see an unrelated bug in there, though.  You are using the name
"restart" both for a string entered by the user and for the name of
the function, which is called recursively.  The name for the string,
which is local, shadows the name for the function, which is global.
So if the program ever hits the third branch of the if statement you
will get an error.

Python doesn't optimize tail-recursion, so you would get a different
error if the user hit that branch enough times (around 1000)
consecutively, as the interpreter hits the stack limit.  For example,
if they just held down the Enter key for a while.  So this looping
would be better accomplished with a while True loop and break
statements than with recursion.

On Thu, Sep 19, 2013 at 12:46 PM, William Bryant <gogobebe2 at gmail.com> wrote:
> the word 'def' has  squiggily lines but the program works fine. It says: Syntax Error: expected an indented block. - why?
>
> def restart():
>     print("""
>
>     ~~~~~~~~~~~~~~~~
>
>     Cacluation DONE!
>
>     ~~~~~~~~~~~~~~~~
>
>     """)
>     restart = input("\nEnter yes if you want to make a new list and no if you want to close the program (yes/no):  ")
>     restart
>     if restart == "yes" or restart == "y" or restart == "new list":
>         print("You want make a new list...\n")
>         time.sleep(1)
>         NOS()
>     elif restart == "no" or restart == "n" or restart == "close":
>         print("Goodbye!")
>         time.sleep(1)
>         print("Goodbye!")
>         time.sleep(1)
>         print("Goodbye!")
>         time.sleep(1)
>         print("Goodbye!")
>         time.sleep(1)
>         print("Goodbye!")
>         time.sleep(1)
>         quit()
>     else:
>         print("type y or n")
>         time.sleep(0.5)
>         restart()
> --
> https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list