Git Product home page Git Product logo

pypart10's Introduction

Part 10

Accompanying resources

Exercise 1

Create a program called small_town_teller.py

Declare a Person class with the following attributes:

  • id
  • first name
  • last name

Declare an Account class with the following attributes:

  • number
  • type
  • owner
  • balance

Declare a Bank class able to support the following operations:

  • Adding a customer to the bank
  • Adding an account to the bank
  • Removing an account from the bank
  • Depositing money into an account
  • Withdrawing money from an account
  • Balance inquiry for a particular account

From an interactive terminal, you should be able to import these classes an interact with the objects and methods defined above.

Constraints

  • When attempting to register a customer, the customer id must be unique.
  • When attempting to add an account, the user associated with said account must already registered as a customer.
  • When attempting to add an account, the account number must be unique.
from small_town_teller import Person, Account, Bank

zc_bank = Bank()
bob = Person(1, "Bob", "Smith")
zc_bank.add_customer(bob)
bob_savings = Account(1001, "SAVINGS", bob)
zc_bank.add_account(bob_savings)
zc_bank.balance_inquiry(1001)
# 0
zc_bank.deposit(1001, 256.02)
zc_bank.balance_inquiry(1001)
# 256.02
zc_bank.withdrawal(1001, 128)
zc_bank.balance_inquiry(1001)
# 128.02

Exercise 2

Create a program called persistent_small_town_teller.py

Declare a PersistenceUtils class with the following static methods:

  • write_pickle
  • load_pickle

Append the following methods to the Bank class:

  • save_data
  • load_data

This application should extend exercise one so that all of the customers and accounts persist between restarts.

From an interactive terminal:

  • Create customers and accounts.
  • Save the data using the save_data method.
  • Exit the session.
  • Create a new session.
  • Validate there are no customers and no accounts.
  • Load the saved data using the load_data method.
  • Validate the persistence is working.
from persistent_small_town_teller import Person, Account, Bank

zc_bank = Bank()
zc_bank.customers
# {}
zc_bank.accounts
# {}
zc_bank.load_data()
zc_bank.customers
# {1: <persistent_small_town_teller.Person object at 0x1098e6a90>}
zc_bank.accounts
# {1001: <persistent_small_town_teller.Account object at 0x1099e04d0>}

pypart10's People

Contributors

nikkiwojo avatar xt0fer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.