0
Can I mak a program return to a previous line?
I program a game, and I want to program an option for a rematch, so I want the program to return to the first line of the game and run it so thd player would be able to make a rematch. I this possible?
4 ответов
+ 2
Earlier I was thinking about misusing exceptions (written with "air quotes"). It turns out that non-local goto's are..."exactly the right way"...perhaps in this case :)
http://bugs.python.org/issue6367
Custom exceptions:
https://en.m.wikibooks.org/wiki/Python_Programming/Exceptions#Custom_Exceptions
0
Kind of, there is no goto, but you can set up functions and use them at a later time
0
To add to Gabriel's post if you don't want to restart entire game (say,you wish to ommit welcome message), you can put those lines you don't want to repeat outside the loop like so:
print "Welcome"
while (player wants to play):
play()
if (player still wants to play):
print "\nWelcome back\n"
else:
print "\nBye"
0
Store them in a function using "def"
So later on you can call the whole game components with just the function name.
Example:
-def play_again()
-"Game components goes here"
-Conditions then
To call all of em,
-play_again()