"The code below is related to ""war"" in the ""self-taught programmer"", but I have a question."Below are the two intra-class functions.I'm still a beginner in programming, and it may be quite rudimentary, but I appreciate your cooperation.
Although there are play_game
and winner
functions inside the Game
class, I have an image that if I want to get something, I can only get it above the appropriate one by Python specification.
However, if you look at the previous two functions, you will find the winner
function below the play_game
function.Is this a phenomenon caused by trying to get a value in the class?Or is there something fundamentally wrong?Please let me know.
class Game:
defplay_game(self):
cards = self.decks.cards
print('Start War'')
whilelen(cards)>=2:
US>Exit with m='q, play with other keys:'
response=input(m)
if response=='q':
break
self.p1.card = self.deck.draw()
self.p2.card = self.deck.draw()
self.print_draw (self.p1, self.p2)
if self.p1.card>self.p2.card:
self.p1.wins+=1
self.print_winner (self.p1)
else:
self.p2.wins+=1
self.print_winner (self.p2)
win=self.winner (self.p1, self.p2)
print('End of Game, Victory of {}'.format(win)))
def winner (self, p1, p2):
if p1.wins>p2.wins:
return p1.name
if p1.wins<p2.wins:
return p2.name
"Return" draw!'
Is this a phenomenon caused by trying to get a value in the class?
No, it's not.The same goes for simple functions.
Or is there something fundamentally wrong?
It doesn't have to be physically written above, and it doesn't matter if it's loaded before the function call.
def funcA():
print('funcA')
funcB()
def funcB():
print('funcB')
funcA()
There is no problem with , but
def funcA():
print('funcA')
funcB()
funcA()
funcA()
def funcB():
print('funcB')
cannot call funcB() within funcA().
549 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
548 Understanding How to Configure Google API Key
727 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
540 Uncaught (inpromise) Error on Electron: An object could not be cloned
548 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.