银行ATM学校的python任务

时间:2015-11-10 19:29:53

标签: python

写一个名为“Bank Of”的银行应用程序。

Bank Of提示输入客户名称和关联的用户名。 Bank Of循环,同时提示:

  1. 创建帐户(支票或储蓄)

  2. 存款

  3. 取款

  4. 从支票账户转账到储蓄账户(反之亦然)

  5. 显示交易记录。

  6. 这是我到目前为止所做的...我需要帮助从chequing转移到储蓄账户..任何帮助将不胜感激。

    print("Hello, Welcome to Shawn's Bank ATM")
    print("")
    print("Please begin with creating an account")
    name=input("Enter your name: ")
    phone=input("Enter your phone number: ")
    address=input("Enter your address: ")
    code=input("Please enter a 4 digit pin to use as your passcode: ")
    
    print()
    print("Your account summary is:")
    print("Name:" + name)
    print("Phone Number:" + phone)     
    print("Address:" + address)
    print("Pin Code:" + code)    
    print()
    balance=float(input("Enter an amount to deposit into the account: "))
    print()
    print(name,", Thank you for creating an account.")
    def printMenu():
        print()
        print("Please choose an option below:")
        print("""
        Enter b to Check your Balance
        Enter d to Deposit money into your Account
        Enter w to Withdraw money from your Account
        Enter q to Quit the Program """)
        print("")
    
    def getTransaction():
        transaction=str(input("What would you like to do? "))
        return transaction
    
    def withdraw(bal,amt):
        global balance
        balance=bal-amt
        if balance<0:
            balance=balance-10
    
    def formatCurrency(amt):
        return "$%.2f" %amt
    
    ###MAIN PROGRAM###
    
    printMenu()
    command=str(getTransaction())
    
    while command!="q":
        if (command=="b"):
            print(name,"Your current balance is",formatCurrency(balance))
            printMenu()
            command=str(getTransaction())
        elif (command=="d"):
            amount=float(input("Amount to deposit? "))
            balance=balance+amount
            printMenu()
            command=str(getTransaction())
        elif (command=="w"):
            amount=float(input("Amount to withdraw? "))
            withdraw(balance,amount)
            printMenu()
            command=str(getTransaction())
        else:
            print("Incorrect command. Please try again.")
            printMenu()
            command=str(getTransaction())
    
    print(name,"Goodbye! See you again soon")
    

1 个答案:

答案 0 :(得分:0)

我会使用帐户类来跟踪多个帐户:

class Account:
    def __init__(self, accNum):
        self.balance = 0.0
        self.accNum = accNum

    def withdrawl(self, amount):
        self.balance -= amount

    # ETC

然后使用主循环打印选项,输入等等。请注意,由于现在有多个帐户,因此用户必须指定要操作的帐户,可能是帐号。将您的帐户对象存储在列表中,以便找到它们:

if UserRequestsNewAccount:
    new = Account(1234)
    ACCOUNTS.append(new)

然后访问它们:

for acc in ACCOUNTS:
    if acc.accNum == RequestedAccountNumber:
        acc.withdraw(amount)

否则,您可以只有一个双打列表并按索引引用它们。但是不那么有趣。 :)

编辑:你的python文件的基本布局应该是这样的:

class Account:
    def __init__(self):
        # fill in code here
    def deposit(self, amount):
        # fill in code here
    def withdraw(self, amount):
        # fill in code here
    def display_history(self):
        # fill in code here

ACCOUNTS = []
def main():
    while 1:
        print "choose an action: 1) new Account \n2) Withdraw .... etc"
        action = raw_input()
        if action == '1':
            print 'enter desired account number: '
            accNum = raw_input()
            new = Account(accNum)
            ACCOUNTS.append(new)
        elif action == '2':
            # fill in code here
        elif action == '3':
            # fill in code here
        elif action == '4':
            # fill in code here

main()

所以我们的想法是声明你的类,然后使用另一个循环来控制这些对象的处理。每个选项都需要一些用户输入来指定要执行的操作,然后调用Account方法。 Account.history可以是一个字符串,您可以在执行操作后附加到该字符串。