M
M
mikki200412021-04-19 00:32:02
Python
mikki20041, 2021-04-19 00:32:02

Add and output result?

Hello everyone, the problem with the program is that it does not add points, each method gives a specific number of points for a specific answer, how to make all points add up?

class Client():
    def __init__(self, full_name = None, age = 0, gender = None, profit = 0, credit_history = 0, credit_amount = 0, points = 0):
        self.full_name = full_name
        self.age = age
        self.gender = gender
        self.profit = profit
        self.credit_history = credit_history
        self.credit_amount = credit_amount
        self.points = points
    
    def age_conditions(self):
        if self.age <= 40:
            self.points += 10
        else:
            self.points += 20
        return self.points
    
    def gender_conditions(self):
        if self.gender.upper() == "Ж":
            self.points += 10
        return self.points
    
    def profit_conditions(self):
        if self.profit <= 40000:
            self.points += 10
        else:
            self.points += 20
        return self.points
    
    def credit_history_conditions(self):
        if self.credit_history.upper() or self.credit_history.lower() == "Да":
            self.points += 20
        return self.points
    
    def credit_amount_conditions(self):
        if self.credit_amount >= 20000:
            self.points += 20
        else:
            self.points += 10
        return self.points
    
    def credit_result(self):
        if self.points <= 50:
            print(f'Кредит успешно оформлен! {self.points}')
        else:
            print(f'В кредите отказано, сумма ваших баллов {self.points}')
        return self.points



bank_client = Client()
bank_client = Client(full_name = input('Введите ваше ФИО: '))
bank_client = Client(age = int(input('Введите ваш возраст: ')))
bank_client.age_conditions()
print(bank_client.points)
bank_client = Client(gender = input('Введите ваш пол (М/Ж): '))
bank_client.gender_conditions()
print(bank_client.points)
bank_client = Client(profit = int(input('Введите ваш ежемесячный доход: ')))
bank_client.profit_conditions()
print(bank_client.points)
bank_client = Client(credit_history = input('Имеется ли у вас кредитная история: '))
bank_client.credit_history_conditions()
print(bank_client.points)
bank_client = Client(credit_amount = int(input('Сумма кредита: ')))
bank_client.credit_amount_conditions()
print(bank_client.points)
bank_client.credit_result()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MinTnt, 2021-04-19
@mikki20041

Well, what can I say... I don't even know where to start... From the fact that you overwrite the same variable every time, starting from scratch, so to speak, or from...
Okay, there are two solutions.
1) Set the required data not by overwriting the variable and calling the class, but by means of bank_client.age =, bank_client.full_name =,
i.e.

bank_client = Client()
bank_client.full_name = input('Введите ваше ФИО: ')
bank_client.age = int(input('Введите ваш возраст: '))
bank_client.age_conditions()
print(bank_client.points)
bank_client.gender = input('Введите ваш пол (М/Ж): ')
bank_client.gender_conditions()
print(bank_client.points)
bank_client.profit = int(input('Введите ваш ежемесячный доход: '))
bank_client.profit_conditions()
print(bank_client.points)
bank_client.credit_history = input('Имеется ли у вас кредитная история: ')
bank_client.credit_history_conditions()
print(bank_client.points)
bank_client.credit_amount = int(input('Сумма кредита: '))
bank_client.credit_amount_conditions()
print(bank_client.points)
bank_client.credit_result()

2) In each subsequent overwriting of the variable, add the data received from the previous call. Well, or, for example, just pass points to each following function. But I think it's redundant work.
bank_client = Client()
bank_client = Client(full_name = input('Введите ваше ФИО: '))
bank_client = Client(age = int(input('Введите ваш возраст: ')), full_name=bank_client.full_name)
bank_client.age_conditions()
print(bank_client.points)
bank_client = Client(gender = input('Введите ваш пол (М/Ж): '), full_name=bank_client.full_name, age=bank_client.age, points=bank_client.points)
bank_client.gender_conditions()
print(bank_client.points)
bank_client = Client(profit = int(input('Введите ваш ежемесячный доход: ')),full_name=bank_client.full_name, age=bank_client.age, gender = bank_client.gender, points=bank_client.points)
bank_client.profit_conditions()
print(bank_client.points)
bank_client = Client(credit_history = input('Имеется ли у вас кредитная история: '), full_name=bank_client.full_name, age=bank_client.age, gender = bank_client.gender, profit = bank_client.profit, points=bank_client.points)
bank_client.credit_history_conditions()
print(bank_client.points)
bank_client = Client(credit_amount = int(input('Сумма кредита: ')), full_name=bank_client.full_name, age=bank_client.age, gender = bank_client.gender, profit = bank_client.profit, credit_history=bank_client.credit_history, points=bank_client.points)
bank_client.credit_amount_conditions()
print(bank_client.points)
bank_client.credit_result()

Ps Although it is clear that the first solution is better. But I just decided that since the author wants to overwrite the variable, I won’t refuse him.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question