When coding in Tkinter, you can make a button, then when the button is pressed, it refers to something that you defined, or whatever its called when you use the def statement.
What I'm wondering, is if there is a way to do this in non Tkinter programing. I am making a text based game that requires a large section of code often, and I was wondering if I could put it off to the side, so to speak, and then whenever I need it, call it using the name I put in front with def.
For example: say I made a guess number program that lets two people take turns. the guess number code is:
import random number = random.randint(1,10) print "choose a number:" while guess != number: num = num + 1 guess = input("Enter guess " + str(num) + ": ") if guess < number: print "Higher..." elif guess > number: print "Lower..." print "Yay you got it in",num,"tries"
That doesn't show the code for multiple players, but I was wondering if I could assign that section of code to some kind of statement that could be called up each time there is a new turn, kind of like how in Tkinter you can call something up every time a button is pressed.
I know this is confusing, I'm having a hard time explaining what I want to know.
I guess what I want is a good goto replacement, because I know python does not have a goto function. I just want to be able to point at other parts of my code, and then when that part is done, have it come back to where it was.