Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this script print an extraneous 'none' in the output
    primarykey
    data
    text
    <p>I've written a simple script to help me better understand using classes. It generates a random character for a game. I defined the object and then call a function on that object that prints out the generated character. At the end of the printed block, there is an extraneous "None" that I'm not sure where it's coming from nor why it's being printed. Here's the sample output:</p> <pre><code>ted Strength : 20 Dexterity : 17 Hit Points: 100 Aura : 100 Weapon : Spell : Item : Element : -------------------- None </code></pre> <p>In my code, the last line of <code>player.stats()</code> is <code>print "-" * 20</code> which is displayed right above "None". Here's the code that defines the object:</p> <pre><code>class Player(object): def __init__(self, name): self.name = name self.strength = randint(15, 20) self.dexterity = randint(15, 20) self.hit_points = 100 self.aura = 100 self.weapon = " " self.spell = " " self.item = " " self.element = " " def stats(self): print "\n" print self.name print "Strength : %d" % self.strength print "Dexterity : %d" % self.dexterity print "Hit Points: %d" % self.hit_points print "Aura : %d" % self.aura print "Weapon : %s" % self.weapon print "Spell : %s" % self.spell print "Item : %s" % self.item print "Element : %s" % self.element print "-" * 20 </code></pre> <p>The object is then instanced using this:</p> <pre><code>name = raw_input("Name your character: ") player = Player(name) print player.stats() </code></pre> <p>The complete code can be read <a href="http://pastebin.com/3apb6M6t" rel="nofollow">here at Pastebin</a> if necessary.</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.
 

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