0

I am having a weird AttributeError

Hey! I am kind of a ghost here in the community, but I've been always learning topics around, but, anyway, jumping out of presentations, I am having a pretty weird problem with a code; Well, first of all, I am not an expert on Python and I like learning things while putting them in practice, that helps me to memorize essential stuff, I hope you guys understand that, so probably you'll have some minor errors on what I am going to show you. Jumping to the problem; I was trying to program a little game with no expectation, just for fun, coding during the free time at the night, and I created a bag system, a weapon system, and a character creation system. All of those are just lame codes but in my bag system I have an additional function, which adds an item to the bag; class Bag(): def __init__(self): self.bag = [] if len(self.bag) > 10: print(""" Sorry, you've reached the limit of your bag. Increase it by buying another bag on the local store or even build your own by hunting """) else: print(self.bag) def bag(self): print(self.bag) def add(self, item): self.bag.append(item) and in the character creation system, after finishing the whole creation, you receive a bag and you also receive a weapon, which is added to your bag; import bagsystem as b import weaponsystem as ws class CreateCharacter: def __init__(self, name): self.name = name self.age = int(input('Type in how old is your character: ')) self.level = 1 self.exp = 1 self.money = 5000 self.points = 50 print('Use your points {}p to add strenght, ability and intelligence for your character! Use it smartly.'.format(self.points)) self.strenght = int(input("Type in how much points you want to add on your character's strenght: ")) if self.strenght > 50: raise Exceptio

19th Oct 2018, 12:25 AM
Philipe Galdino
Philipe Galdino - avatar
1 Respuesta
0
Your code reached the web version post limit and was truncated. Please share your code to copy a link to the clipboard and paste it in a response to this thread. Your bag limit code is in the wrong place. It will never execute as the bag is empty in the ___init___ method. It should be in the add method to prevent the append call, when full.
19th Oct 2018, 1:27 AM
John Wells
John Wells - avatar