Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're reinitializing the class every time you call it. Here's a cleaner version:</p> <pre><code>class Sparring(): def __init__(self, mywins, hiswins): self.mywins = mywins self.hiswins = hiswins def i_win(self): self.mywins += 1 def he_wins(self): self.hiswins += 1 def __repr__(self): return "My wins: {}; his wins: {}".format(self.mywins,self.hiswins) 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?" fight = Sparring(0,0) dodge = raw_input() if 'right' in dodge: print "Nice job, you knocked him out!" fight.i_win() else: print 'Oh no he knocked you out' fight.he_wins(1) print fight fight_match() </code></pre> <p>In this code, <code>Sparring()</code> is a class with two functions, <code>he_wins()</code> and <code>i_win()</code>. If he wins, run <code>he_wins()</code>; if you win, run <code>i_win()</code>.</p> <p>In <code>fight_match()</code>, you'll see that we create <code>fight</code>, which is a <code>Sparring</code> object&mdash;which means that it has all the methods and variables of the <code>Sparring</code> class (remember, you don't interact with a class directly&mdash;you interact with <em>objects</em> of that class). So then we accept one <code>raw_input()</code>, <code>dodge</code>. If this input is "right", then we <strong>update the fight object to reflect one win for us</strong> (by using <code>i_win()</code>). If not, then he wins...so we do <code>fight.he_wins()</code>, which updates the <code>fight</code> object to reflect that he won.</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    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