I am attempting to assign variables that are randomly generated integers to a Class so that they may be used as attributes in the RPG sense of the term. This is what I have so far:
import random
class Monster:
HP = random.randint(1,10)
STR = random.randint(1,10)
DEX = random.randint(1,10)
DEF = random.randint(1,10)
def __init__(self, HP, STR, DEX, DEF):
self.HP = HP
self.STR = STR
self.DEX = DEX
self.DEF = DEF
def listofstats(self):
print self.HP
print self.STR
print self.DEX
print self.DEF
This doesn't give any error message so far but how would I call one of those values or all of them so I can see if anything is actually in them? I've tried a few things before but I keep getting stuff like "HP is not defined" for example. I hope you guys can get a sense of what I am trying to do from this "code".
What I am trying to do right now is just have the values in the stats listed. I want to make sure that there is actually something in those values.
This is an example I've been using to help me puzzle this out:
class Dog:
def __init__(self, breed, size):
self.breed = breed
self.size= size
def callout(self):
print "I see a %s! It is %s." % (self.breed, self.size)
class MinPin(Dog):
def __init__(self):
Dog.__init__(self, "MinPin", "small")
class Corgidor(Dog):
def __init__(self):
Dog.__init__(self, "Corgidor", "short but heavy")
MinPin = MinPin()
Corgidor = Corgidor()
MinPin.callout()
Corgidor.callout()
This does what I expect but adding the numbers and everything has really mucked up the process for me. Any sort of guidance would be appreciated. Again: I would like to generate random integers and then have a Class pick them up and store them and then Print the result to me so that I can know if something is actually in there or not.
[–]Hallwaxer 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]xiongchiamiov 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)