Else statement executing when it shouldnt

Chris Angelico rosuav at gmail.com
Sun Jan 20 23:52:12 EST 2013


On Mon, Jan 21, 2013 at 3:40 PM, eli m <techgeek201 at gmail.com> wrote:
> an else statement is running when it shouldnt be. It is on the last line. Whenever i am in the math or game function, when i type in main, it goes back to the start of the program, but it also says not a valid function. I am stumped!

Check your indentation levels. I see a few things here that look odd:

>     if function == "help":
>         while helpfunc == 0:
>             if helpmain == "main":
>         else:

What is the else meant to bind to? The innermost if? The 'if function
== "help"'? It's currently binding to the while.

Recommendation: Break this up! Your main loop is huge! It's way too
easy to get lost in it. And while you're at it, consider unifying some
of the similar blocks of code. The solution to both issues is simple:
Use functions. Have you been taught about them yet?

Also, side tip: Be honest about homework. I'm fairly sure that's what
this is. :)

ChrisA



More information about the Python-list mailing list