I am very new to programming in Python and I just had a question as to why when I call a function it doesn't work. I see the TypeError
about die_roll
needing two arguments but why isn't that covered by self.result
when added to the parenthesis?
import random
def die_roll(self, result):
self.result = random.randint(1, 10)
print "Roll the dice, Dennis. "
print "You have rolled a %s!" % self.result
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print (" Welcome... ")
print (" TO THE WORST GAME IN THE WORLD!!!!!!!!!!! ")
print (" REALLY, IT IS QUITE BAD. YOU'LL SEE...... ")
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
name = raw_input('Welcome to this awful adventure. Please enter your name to get started: \n')
print "\n%s? I don't like that name. \n" % (name)
name1 = raw_input('Try again: \n')
print "\n%s?! Really? That's the best you can do? You know what - just forget it. You will be called Dennis. \n" % (name1)
print "I happen to like Dennis. It's a good name. Regal. It's nice to meet you.... Dennis. \n"
print "You begin your adventure peering into a long, gloomy cave. You move by rolling a 10-sided dice.\n"
print "You will encounter random enemies along the way. If your combined rolls equal 100, you win!\n"
die_roll()
You are defining your function as
This tells python interpreter that die_roll , needs two arguments self and result.
I am guessing you copied this method from within some other class, because self is the normal naming convention for the first parameter to a method in a class, in the later case, self (first parameter) refers to 'this' (from c++ or java) .
From the function body, it seems like you do not need any parameters, maybe you can try -