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()) 

  1. unless i'm missing notation, q terrible name. variable , method names should in lowercase, , describe purpose of variable. board_width better name.

  2. having method same name class member confusing. since you're asking board size, i'd rename method ask_board_size.

  3. 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

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -