Sep-03-2019, 07:51 PM
First of all, that needs to be
That does not reset your scores, but if you copy and paste the initial values of the scores from play_game, that will work. Mostly. I'm assuming you would call won from play_game, but then won calls play_game. This is called recursion (a function calling itself), and while it is supported in Python, there are limits to it in Python. I would avoid it unless there's a good reason.
Instead, I would write a reset method that just reset the scores to 0. Then put the code from play_game in a while loop:
def win(self):
. You need the closing parenthesis and the colon to have proper syntax. And assuming this is a method of Game, the self parameter will be automatically provided and you need to be ready for that.That does not reset your scores, but if you copy and paste the initial values of the scores from play_game, that will work. Mostly. I'm assuming you would call won from play_game, but then won calls play_game. This is called recursion (a function calling itself), and while it is supported in Python, there are limits to it in Python. I would avoid it unless there's a good reason.
Instead, I would write a reset method that just reset the scores to 0. Then put the code from play_game in a while loop:
while True: # play the game code here q = input("do you want to play again ? yes or no ?") if q == 'yes': self.reset() else: breakThat way the scores will be reset if they want to play again, and the program will end if they don't.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures