SHARE
TWEET

Banking Ex

catehstn Jun 20th, 2014 210 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Bank account object - it's just a collection of variables.
  2. class BankAccount(object):
  3.     name = ""
  4.     balance = 0
  5.     pin = ""
  6.  
  7.     # The class "constructor" - It's actually an initializer
  8.     def __init__(self, name, balance, pin):
  9.         self.name = name
  10.         self.balance = balance
  11.         self.pin = pin
  12.  
  13.     # How we print a string
  14.     def __repr__(self):
  15.         return "name: " + self.name + "\nbalance : " + str(self.balance) + "\npin: " + self.pin;
  16.  
  17. # Makes a bank account (calls the "constructor").
  18. def make_bank_account(name, balance, pin):
  19.     return BankAccount(name, balance, pin);
  20.  
  21. # Where we do out work.
  22. def banking():
  23.     name = "";
  24.     # Get the user's name, save it in the "name" variable.
  25.     pin = "";
  26.     # Have the user choose a pin, save it in the "pin" variable.
  27.     # Make sure it has at least 4 characters.
  28.     while(len(pin) < 4):
  29.         # Fill this bit in!
  30.         break; # Delete this line once you put in your own code
  31.  
  32.     # This makes a new bank account object, and prints it out.
  33.     bankAccount = make_bank_account(name, 0, pin);
  34.     print("You have a bank account!");
  35.     print(bankAccount);
  36.  
  37.     # Now we can start banking.
  38.     # This means it will loop forever.
  39.     while(True):
  40.         break; # Delete this line once you put in your own code
  41.         # Ask the user if they want to pay in or withdraw money.
  42.         # Ask for the amount.
  43.         # If they are withdrawing, take that amount away from their balance.
  44.         # If they are paying in, add that money to their balance.
  45.         # Print out their new balance.
  46.  
  47. # main method, called when you run the program.
  48. if __name__=='__main__':
  49.     banking();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top