UPDATE: Disregard, please... Just noticed I had a print on nameit(self), rather than return.
Good evening, everyone!
I've taken to learn python as a hobby, and, at the moment, I'm on the 19th lesson (Intro to classes). While I'm learning, I like to try and apply what I've learned by creating a simple project.
Right now I'm trying my hand at classes. The project I'm attempting to do with classes is an adventurer shopping at a weapons store. It'll have inventory tracking, gold tracking and so forth, trying to use as much as I've learned so far. Usually I can either figure out what am I doing wrong, either by Googling, or taking a break and approaching the issue at a different angle.
However, I got a question I couldn't find the answer. Right now I'm working on a script that generates random items for purchase:
from random import randrange prefixes = ["Menacing", "Strong", "Exquisite", "Weak", "Nice looking"] materials = ["Steel", "Mithril", "Cardboard", "Iron", "Diamond", "Paper"] suffixes = ["of Death", "of Life", "of Uselessness", "of Defense", "of Vitalty"] tipos = ["Sword", "Dagger", "Bow", "Axe"] class Weapon(object): def __init__(self, prefix, material, tipo, suffix): self.prefix = prefix self.material = material self.tipo = tipo self.suffix = suffix def nameit(self): seq = (self.prefix,self.material,self.tipo,self.suffix) print (" ".join(seq)) def openstore(y): available = for x in range(y): available.append((Weapon(prefixes[randrange(len(prefixes))],materials[randrange(len(materials))],tipos[randrange(len(tipos))],suffixes[randrange(len(suffixes))])).nameit()) print("Done")
Apart from an ugly way to generate random items (I'll work on that later), the issue I'm having is that when I run openstore(10) (I'm using Python 3.5.1, by the way), for example, it prints all the 10 items, while here on codeacademy, it doesn't. How can I append the items without printing the result yet? (Later, this list of items will be paired up with a prices list - or maybe have the price on the class itself, but that's something for another post )