440,630 Members | 1,252 Online
Need help? Post your question and get tips & solutions from a community of 440,630 IT Pros & Developers. It's quick & easy.

Is there something similar to GOTO in python?

 P: 4 So I'm trying to write a text based adventure game and there are going to be points where you'll have to travel back to previous rooms. I wasn't really sure of the best way to go about this. Also along the way you'll collect 3 keys and various loot. any help would be great. thanks -Matt Expand|Select|Wrap|Line Numbers #Doors test   def main():       endprogram = 'no'       while endprogram == "no"           health = 100         loot = 0         key1='no'         key2='no'         key3='no'           print "Welcome to Three Keys"         print "++++++++++++++++"         print "All choices are to be typed in lowercase"         print "Find the three keys to access the treasure"         print "There are many dangers and secrets to find"         print "Be mindful of hints and keep your wits about you"   def firstroom():       print "Before you you see three doors   def armory(): def library(): def baths(): def keyroom1(): def keyroom2(): def keyroom3(): def dinning(): def spiral(): def dungeon(): def throneroom():   Nov 29 '10 #1
5 Replies

 Expert Mod 2.5K+ P: 2,851 There is no GOTO in Python. You can call a function based on a condition. By designing your code as objects (functions and classes), you can accomplish the same thing. Nov 30 '10 #2

 P: 4 I'm a bit of a noob when it comes to coding as of now. Is there any chance you could explain that slightly more in depth? Nov 30 '10 #3

 Expert Mod 2.5K+ P: 2,851 A simple example: Expand|Select|Wrap|Line Numbers if condition == "X":     start() elif condition == "Y":     continue_to_next_level() Nov 30 '10 #4

 Expert 100+ P: 621 For information only, there is a goto add-on for Python. And the fact that most programmers don't even know it exists says enough about how much it gets used. Nov 30 '10 #5

 P: 30 Goto, break, and continue are bad coding style to many, because they don't follow natural code flow. Dec 5 '10 #6