Oct-14-2016, 08:49 PM
my code is:
to have a method/function that will add 2 valuables together and print the result.how ever each time i call one variable i want to add it add it to an other variable no mater which object it call on. for example i want to all add the variable 'mov' to be added to d and the variable 'act' to i. so it seams unnecessary to enter both. instead have the program figure out the other. for example if i called i call it on 'mov' for to figure out i needs to add it to 'd'.I am trying to do to it with a if then statement and looking up a variable in a list. how ever i need to to know it looking for variable name and not the value. from what i here it hard to do how do i do or achieve the same things with a different means.
class char(object): 'chactors' def __init__(self,name,d,i): self.name = name self.d = int(d) def namechar(self): print self.name def action(self,skill): if in listd: stat = d elsif in listi: stat =i else: pass t = skill + stat print t listd =['mov'] listi =['act'] char1 = char('q','1','2') setattr(char1, "mov", 10) setattr(char1,'act', 100) print char1.mov char1.action('mov') char1.action('act')What I am trying to do:
to have a method/function that will add 2 valuables together and print the result.how ever each time i call one variable i want to add it add it to an other variable no mater which object it call on. for example i want to all add the variable 'mov' to be added to d and the variable 'act' to i. so it seams unnecessary to enter both. instead have the program figure out the other. for example if i called i call it on 'mov' for to figure out i needs to add it to 'd'.I am trying to do to it with a if then statement and looking up a variable in a list. how ever i need to to know it looking for variable name and not the value. from what i here it hard to do how do i do or achieve the same things with a different means.