Category : class

I’m writing a script for a deck of card in an OO way as shown below. class Deck: def __init__(self): self.card_list = self.build() def build(self): suit = ["S", "H", "D", "C"] val = ["ace", "two", "thr", "fou", "fiv", "six", "sev", "eig", "nin", "ten", "jac", "que", "kin"] return list(itertools.product(suit, val)) def deal(self): cards = random.choices(population=self.card_list, k=3) ..

Read more

class Employee: pay_raise_percent = 0 def __init__(self, name, salary): self.name = name self.salary = salary p1 = Employee(‘John’, 50_000) p2 = Employee(‘Alex’, 75_000) p3 = Employee(‘Caleb’, 90_000) Employee.pay_raise_percent = 1.04 print(p1.salary, p2.salary, p3.salary, sep=’n’) # 52000 78000 93600 is it possible to make it so that changing a class attribute leads to an automatic increase ..

Read more

In class FTM I have method check_data_format_input_data class FTM(): def __init__(self, input_data): self.check_data_format_input_data(input_data) self.input_data= input_data #SOME CODE def check_data_format_input_data(self, input_data): #SOME CODE return In class Topic_embedding, I want to use the check_data_format_input_data method from FTM. class Topic_embedding: def __init__(self, input_data): FTM.check_data_format_input_data(input_data = self.input_data) self.input_data= input_data The code above raises: TypeError: check_data_format_input_data() missing 1 required positional ..

Read more

class Login(QMainWindow): def __init__(self): super(Login,self).__init__() loadUi("gui.ui",self) self.startButton.clicked.connect(self.startfunction) self.stopButton.clicked.connect(self.stopfunction) def startfunction(self): self.lcdNumber_4.display(0) I’m trying to call startfunction from outside the class I have tried: CLASS = Login() CLASS.startfunction() I think it has to do with the QMainWindow argument it takes Source: Python..

Read more

I get error printing result.age, why? How I can fix it? import random names = [‘Bob’, ‘Robert’, ‘Tom’] result = random.choices(names, weights=[5, 10, 12], k=random.randint(1, 3)) print(result) class People: def __init__(self, age, city): self.age = age self.city = city Bob = People(’23’, ‘NewYork’) Robert = People(’73’, ‘Boston’) Tom = People(’43’, ‘Oslo’) print(result.age) Source: Python..

Read more