#! /usr/bin/env python # -*- coding: utf-8 -*- """ Python solution for the Problem III.1 of the CS101 Final Exam (OOP). @date: Thu Apr 23 19:08:05 2015. @author: Lilian Besson for CS101 course at Mahindra Ecole Centrale 2015. @licence: MIT Licence (http://lbesson.mit-license.org). """ # %% First class account class account(): int_rate = 0.09 def __init__(self, account_number, init_deposite): # Syntax error, self was not passed as an argument self.accnt_num = account_number self.init_deposite = init_deposite # Syntax error, balance was not the argument but init_deposite is def deposit(self, amount): """ Function to deposit money to an account.""" self.balance += amount # Semantic error, for deposit, money should be added, not removed. return self.balance def calc_interest(self): """ Function to calculate half yearly interest returns both interest and latest balance.""" interest = self.balance * account.int_rate * 0.5 # Syntax error, int_rate cannot be directly accessed, # it needs to be read from the class account self.balance += interest # return interest # Semantic error, self.balance will not be returned if we return the interest return self.balance # %% Second class savings, inherited from account class savings(account): # Syntax error. While inheriting, self is not required. def calc_interest(self, n): interest = self.balance * n * account.int_rate # Syntax error. self.n was not defined. Only n return interest def change_accnt_num(self, new_accnt_num): self.accnt_num = new_accnt_num # %% Examples my_account = account(1234, 20000) # Syntax error: init parameters was not given print my_account my_account.change_accnt_num(3456) # Syntax error: account class has no method change_accnt_num