Managing classes in Python programming -
update
tells me
typeerror: __init__() missing 1 required positional argument: 'storlek'
my class
class hanterare: def __init__(self, storlek): self.storlek =storlek my functions
def fråga_storlek(): try: hanterare().storlek =int(input('choose size')) except valueerror: print("wrong try again!!") fråga_storlek() and want use value, user has chosen , call them other functions example:
def getnewboard(): board = [] in range(fråga_storlek()): board.append([' '] * fråga_storlek())
unless i'm missing notation,
qterrible name. variable , method names should in lowercase, , describe purpose of variable.board_widthbetter name.having method same name class member confusing. since you're asking board size, i'd rename method
ask_board_size.after taking above consideration, problem solves itself:
class boardhandler(self, board_size): self.board_size = board_size def ask_board_size(self): try: self.board_size = int(input("choose size please")) except valueerror: print("wrong try again!") ask_board_size() and constructor new notation? should use __init__:
class boardhandler: def __init__(self, board_size): self.board_size = board_size ...
Comments
Post a Comment