Not to be rude, but that code is pretty poorly written. I tried dissecting it to figure out what the heck was going on and had absolutely no luck. Consider eliminating the parts that aren't necessary to your question. If required, write a new script, illustrating your goal and what went wrong.
Just some general advice for any issues you encounter:
-Add plenty of 'debug' lines (that is, print statements that log where you are at in the code) around the problematic code to pinpoint the direct issue you are having.
-If you are planning on getting serious about programming, join a site like Stack Overflow (you can get more precise and accurate answers there) and learn how to ask good questions.
-Lastly, use consistent naming conventions. Variable names like imput is pretty confusing and makes understanding your code really hard.
Good luck with your programming! Once you fix your question or post on Stack Overflow reply to this answer and I'll get back with you.