Created
August 30, 2010 23:41
-
-
Save erinxocon/65a082ec654f4f2686cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#=============================================================================== | |
# lab7.py | |
# Student Name: Michael O'Connell | |
# Assignment: Lab #7 | |
# Submission Date: 11/05/2008 | |
# Honor Code Statement: I received no assistance on this assignment that | |
# violates the guidelines as set forth by the instructor | |
# and the class syllabus. | |
# References: Blackboard Forums, Python Texts, Lab and Class Slides, http://forums.devshed.com/python-programming-11/password-input-100483.html for the getpass help | |
# Comments: Over all no major problems, figuring out how to use the dictionaries was a little tough. Instead of using a raw_input for the | |
# pin_inputs, I masked them with getpass, which is very very nifty to mask the input and output. | |
#=============================================================================== | |
import os, getpass | |
class Account(object): | |
counter = 1 | |
dictionary = {} | |
#My constructor method that assembles the dictionary and generates unique account id's | |
def __init__(self, name, pin, balance): | |
self.__name = name | |
self.__pin = pin | |
self.__balance = balance | |
self.__id = Account.counter*(ord(name[0])+ord(name[len(name)-1])) | |
Account.counter += 1 | |
Account.dictionary[str(self.__id)] = [self.__pin,self.__balance,self.__name] | |
#Formats my strings for priting after the user creates a new account | |
def __str__(self): | |
return 'Your User ID is: '+str(self.__id)+'\nYour starting Balance is: $'+('%.2f') %(self.__balance) | |
#Used to get the name of an account | |
def get_name(self, account_id): | |
return Account.dictionary[account_id][2] | |
#Used to get the balance from the specific account | |
def get_balance(self, account_id): | |
return Account.dictionary[account_id][1] | |
#checks the input pin with the pin stored in the dictionary | |
def check_pin(self,account_id, in_pin): | |
if Account.dictionary[account_id][0] == in_pin: | |
return True | |
else: | |
return False | |
#Add's money to the account | |
def deposit(self, account_id, amt_dpst): | |
Account.dictionary[account_id][1] += amt_dpst | |
#Takes away money from the account | |
def withdraw(self, account_id, amt_wthdrw): | |
Account.dictionary[account_id][1] -= amt_wthdrw | |
balance = property(get_balance) | |
def clear(num_lines = 1000): | |
#Clear Screen function, can detect UNIX, and Windows, if other prints 1000 lines | |
if os.name == "posix": | |
os.system("clear") | |
elif os.name == "nt": | |
os.system("CLS") | |
else: | |
print ("\n"*num_lines) | |
def main(): | |
#Establishes the main menu strings for printing later | |
welcome_message = 'Welcome To The Awesome Bank ATM' | |
main_menu = ''' | |
1) Create a New Account | |
2) Log into an Existing Account | |
3) Exit''' | |
new_account = 'New Account Information' | |
sub_menu = ''' | |
1) Deposit Money | |
2) Withdraw Money | |
3) Close My Account | |
4) Log Out''' | |
important_msg = '\nWRITE THIS INFORMATION DOWN FOR YOUR RECORDS' | |
while 1: | |
#Initializes my first of many while loops for a menu system | |
clear() | |
print welcome_message | |
print(len(welcome_message)*'-') | |
print main_menu | |
choice = raw_input('\nHow can we help you today?\n\n Please Select an Option: ') | |
#Creates a new user according to the Account Class | |
if choice == '1': | |
clear() | |
print(new_account) | |
print(len(new_account)*'-') | |
usr_name = raw_input('\nWhat is your name? ') | |
usr_pin = getpass.getpass('\nPlease Enter a Pin Number: ') | |
usr_balance = input('\nWhat is your initial deposit size? $') | |
account_info = Account(usr_name, usr_pin, usr_balance) | |
clear() | |
print important_msg | |
print(len(important_msg)*'-') | |
print account_info | |
raw_input('\n\n\tPress Enter to Continue...') | |
#Allows a user to log in | |
elif choice == '2': | |
clear() | |
dummy = 1 | |
# dummy2 = 1 | |
dummy3 = 1 | |
# while dummy2 == 1: | |
clear() | |
#Checks to see if the user ID exists | |
account_id = raw_input('Enter in Your User ID: ') | |
if account_id in account_info.dictionary: | |
sub_count = 0 | |
while dummy3 == 1: | |
clear() | |
#Only allows a pin to be entered 4 times until it rests to the main menu | |
if sub_count > 3: | |
raw_input("You've tried to log in too many times, please try again later...") | |
dummy3 = 0 | |
elif sub_count <= 3: | |
#Tests the pin | |
in_pin = getpass.getpass('\nEnter in Your Pin Number: ') | |
x = account_info.check_pin(account_id, in_pin) | |
if x == True: | |
while dummy == 1: | |
clear() | |
#Gives access to the account | |
sub_menu_welcome = 'Welcome %s!' %(account_info.get_name(account_id)) | |
print(sub_menu_welcome) | |
print(len(sub_menu_welcome)*'-') | |
print('\n Your Current Balance is $%.2f') %(account_info.get_balance(account_id)) | |
print(sub_menu) | |
sub_choice = choice = raw_input('\nPlease Select an Option: ') | |
if sub_choice == '1': #Uses the deposit method i created | |
dummy5 = 1 | |
while dummy5 == 1: | |
clear() | |
print('How much money would you like to deposit?') | |
amt_dpst = input('\n\tEnter amount: $') | |
if amt_dpst >= 0: | |
account_info.deposit(account_id, amt_dpst) | |
print('\nYour new balance is $%.2f') %(account_info.get_balance(account_id)) | |
raw_input('\n\tPress Enter to Continue...') | |
dummy5 = 0 | |
elif amt_dpst < 0: | |
raw_input('Negative Values are not aloud. Press Enter to try again...') | |
else: | |
raw_input('That is an incorrect response, please press Enter to try again...') | |
elif sub_choice == '2': #Uses the withdraw i created, notifies user if they go under $0 | |
dummy6 = 1 | |
while dummy6 == 1: | |
clear() | |
print('How much money would you like to withdraw?') | |
amt_dpst = input('\n\tEnter amount: $') | |
if amt_dpst >= 0: | |
account_info.withdraw(account_id, amt_dpst) | |
if account_info.get_balance(account_id) >= 0: | |
print('\nYour new balance is $%.2f') %(account_info.get_balance(account_id)) | |
raw_input('\n\tPress Enter to Continue...') | |
dummy6 = 0 | |
elif account_info.get_balance(account_id) < 0: | |
print('\nYour account is now overdrawn by $%.2f') %(account_info.get_balance(account_id)) | |
raw_input('\n\nIf this value is not paid back within 10 days penalties will incur.\n\tPress Enter to Continue...') | |
dummy6 = 0 | |
elif amt_dpst < 0: | |
raw_input('Negative Values are not aloud. Press Enter to try again...') | |
else: | |
raw_input('That is an incorrect response, please press Enter to try again...') | |
elif sub_choice == '3': #Deletes user from the dictionary | |
clear() | |
yesno = raw_input('Are you sure you want to delete your account with Awesome Bank? [y/n] ') | |
if yesno == 'y': | |
del account_info.dictionary[account_id] | |
dummy = 0 | |
dummy2 = 0 | |
dummy3 = 0 | |
elif yesno == 'n': | |
continue | |
else: | |
raw_input('That is an incorrect response, please press Enter to try again...') | |
elif sub_choice == '4': #Exits to the main Menu | |
dummy = 0 | |
dummy2 = 0 | |
dummy3 = 0 | |
else: | |
raw_input('That is an incorrect response, please press Enter to try again...') | |
elif x == False: | |
raw_input('Incorrect pin! Press Enter to try again') | |
sub_count += 1 | |
elif account_id not in account_info.dictionary: | |
raw_input('That user name does not exist! Press Enter to try again...') | |
elif choice == '3': | |
clear() | |
break | |
else: | |
raw_input('That is an incorrect response, please press Enter to try again...') | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment