Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is sufficient to simply increment the counters:</p> <pre><code>class Sparring(): def __init__(self, mywins = 0, hiswins = 0): self.mywins = mywins self.hiswins = hiswins def my_score(self): self.mywins += 1 def his_score(self): self.hiswins += 1 @property def best (self): return max ( [self.mywins, self.hiswins] ) </code></pre> <p>You need the function "best" for your check 'fight1 != 2', which now should red 'fight1.best != 2'. Your program could read:</p> <pre><code>def fight_match(): print "Okay you're in the ring, ready to go three rounds with this dude" print "He throws a left hook, which way will you dodge?" dodge = raw_input() fight1 = Sparring() while fight1.best != 2: if 'right' in dodge: print "Nice job, you knocked him out!" fight1.my_score() else: print 'Oh no he knocked you out' fight1.his_score() </code></pre> <p>Another thing is, that you will probably want to move your input into the while loop:</p> <pre><code> fight1 = Sparring() while fight1.best != 2: dodge = raw_input() if 'right' in dodge: print "Nice job, you knocked him out!" fight1.my_score() else: print 'Oh no he knocked you out' fight1.his_score() </code></pre> <p>In order to answer your comment, I will provide a sample implementatio of a whole fight:</p> <pre><code>import random class Fight: def __init__ (self): self.scores = [0, 0] def heScores (self): self.scores [1] += 1 def youScore (self): self.scores [0] += 1 @property def best (self): return max (self.scores) @property def winner (self): return 'You win.' if self.scores [0] &gt; self.scores [1] else 'He wins.' fight = Fight () print ('Fight begins.') question, answer = 'left', 'right' while fight.best != 2: if random.randint (0, 1): question, answer = answer, question if answer in input ('He throws a {} hook, which way will you dodge? '.format (question) ): print ('Nice job, you knocked him out.') fight.youScore () else: print ('Oh no, he knocked you out.') fight.heScores () print (fight.winner) </code></pre> <p>Just for completeness's sake and in order to do some code golfing, this is the one-liner which does the same:</p> <pre><code>_ = [print ('Fight!'), print ('You won.' if (lambda a, b: (lambda a, *b: a (a, *b) ) ( (lambda a, b, c, d, e: e if max (e) == 2 else a (a, b, c, c (b), [print ('Nice job, you knocked him out.'), (1 + e [0], 0 + e [1] )] [1] if d [1] in input ('He throws a {} hook, which way will you dodge? '.format (d [0] ) ) else [print ('Oh no, he knocked you out.'), (0 + e [0], 1 + e [1] )] [1] ) ), b, a, a (b), (0, 0) ) ) ( (lambda a: ('left', 'right') if a.randint (0, 1) else ('right', 'left') ), __import__ ('random') ) [0] == 2 else 'He won.') ] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload