![]() |
|
[Python] Start is not defined - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Start is not defined (/showthread.php?tid=5711857) |
Start is not defined - Deevez - Sep 6, 2017 After noon everybody. So, I'm piecing together just a basic project for school to help teach the students who are just starting Python. Now, I'm running into an issue that is really confusing me. Maybe you guys can help me out. Code import sysSo basically the issue, is that upon running the module, I get through the first stage which is the welcome menu. But once you press "1", it's supposed to go to "start", however it comes back with "start is not defined". I've tried removing the def and un-indenting everything. Someone suggested making a variable called start. I've tried a range of different solutions and it always goes back to "Start is not defined". * - Charger - Sep 6, 2017 I'm pretty sure start needs to be defined before you call it unless you do the main contructor at the end. * - Deevez - Sep 6, 2017 (Sep 6, 2017 09:43 AM)Charger Wrote: I'm pretty sure start needs to be defined before you call it unless you do the main contructor at the end. How would you define start before it is called? * - Nachfolger - Sep 6, 2017 Have you tried changing the function name? I don't know python, but it could be a protected word. * - Charger - Sep 6, 2017 (Sep 6, 2017 09:45 AM)Deevez Wrote: How would you define start before it is called? Logically you don't Have all of your functions in what ever order but at the end of your file is where to invoke the script. https://stackoverflow.com/questions/4041238/why-use-def-main * - Deevez - Sep 6, 2017 (Sep 6, 2017 09:47 AM)Charger Wrote: Logically you don't This is extremely helpful, I'll get to work and see where I end up. Thank you! (Sep 6, 2017 09:47 AM)Charger Wrote: Logically you don't So here's something. A classmate of mine who is helping me out showed me his code. And his works "flawlessly" (as far as his functions go, user input for a name not so much). Code # Name: ScarletJett DevelopmentAnd looking at it, his is set up exactly like mine roughly. Why is it that his works and mine doesn't? * - TheMarkMan - Sep 6, 2017 The issue is exacty what charger said. Look at your friends code. He defines a function called main before he defines start, but he does not call main/run any code until after all the functions have been defined * - Charger - Sep 6, 2017 (Sep 6, 2017 10:05 AM)TheMarkMan Wrote: The issue is exacty what charger said. Look at your friends code. He declares a function called main before he declares start, but he does not call main/run any code until after all the functions have been defined This. Python is executed top to bottom like many languages. You can't call anything before it exists. The code I provided simply tells Python to execute this function when the script has been loaded. * - Deevez - Sep 6, 2017 (Sep 6, 2017 10:05 AM)TheMarkMan Wrote: The issue is exacty what charger said. Look at your friends code. He defines a function called main before he defines start, but he does not call main/run any code until after all the functions have been defined Fixed. Stupid and simple. Thank you, it works fine now! * - koolkid - Sep 6, 2017 (Sep 6, 2017 09:40 AM)Deevez Wrote: After noon everybody. So, I'm piecing together just a basic project for school to help teach the students who are just starting Python. Now, I'm running into an issue that is really confusing me. Maybe you guys can help me out. nice i see the error put the start function at the start of your code. are you planning on building a dungeon game ?? |