INFO I210: Lab 11

Bank Account Class

Coding Standards through Chapter 10 apply to this lab. Pay particular attention to the rules of style for classes, rules added in Chapter 10.

Write a Python Account class, representing a savings account, with the following constructor and methods:

Note: Use the normal Python class syntax, not any alternative using closures, lists, or dictionaries to "implement objects" which may have been taught by way of introduction.

Here's a sample session, to suggest how it should work:

>>> myAccount = Account(1592)
>>> myAccount.getAcctNum()
1592
>>> myAccount.getBalance()
0
>>> myAccount.deposit(100)
>>> myAccount.deposit(200)
>>> myAccount.withdraw(50)
>>> myAccount.getBalance()
250
>>> myAccount.deposit(-100)
Please deposit an amount greater than 0.
>>> myAccount.withdraw(10000)
Insufficient funds.

Testing: Test in the IDLE "Python shell" as specified in the test procedure below and save the session (at the end) as a text file (.txt).

Test procedure: Create an account. Show the account number. Show the balance. Deposit 50, then 250, and show the balance. Withdraw 10, and show the balance. Attempt to deposit −2000. Attempt to withdraw 2000. Show the balance.

Turning in Your Work

Turn in the following in Oncourse Assignments 2, with the given file extensions:

Grading and Assessment

10-1 (CLASS) CA SUBTOTAL: 11 points, 9 to "pass." This is not recorded separately, and it is not "all or nothing." If you earn significantly less than passing, you may get a chance to resubmit; but do try to get it all right the first time!