Can I mak a program return to a previous line? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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?

6th Nov 2016, 9:21 PM
alon lotan
alon lotan - avatar
4 Answers
+ 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
6th Nov 2016, 11:11 PM
Kirk Schafer
Kirk Schafer - avatar
0
Kind of, there is no goto, but you can set up functions and use them at a later time
6th Nov 2016, 9:49 PM
Josh Maloy
Josh Maloy - avatar
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"
7th Nov 2016, 3:36 PM
Chris
Chris - avatar
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()
7th Nov 2016, 5:33 PM
Rumer Obnamia
Rumer Obnamia - avatar