坚持作业。至少部分内容。 ATM银行业务选择

时间:2017-11-29 22:17:53

标签: python python-3.x

下面是我的代码,我已经努力让这个银行atm任务进行。我似乎无法添加和减去代码的平衡。我很确定我做错了什么。以下是作业所涉及的部分内容。在选择选项P,S和E方面,其他所有工作正常。选项D和W是我遇到问题的地方。任何帮助都会很棒。谢谢!

如果用户键入D,则: ·询问用户帐号。 ·在accountnumbers()数组中搜索该帐号并找到其位置。 ·询问用户要存入的金额。 ·将存款金额添加到该帐户的余额中。 ·如果用户键入W,则: ·询问用户帐号。 ·在accountnumbers()数组中搜索该帐号并找到其位置。 ·询问用户要提取的金额。 ·从该帐户的余额中减去提款金额。

namelist=[]
accountnumberslist=[]
balancelist=[]

def populatelist():
    print ('Great! Please enter the information below')
    namecount=0
    #This loops collects the five names,accounts,balances, and appends them to the namelist
    while(namecount< 2):
        name= input('Enter a name: ')
        namelist.append(name)
        accountnumber = input('Please enter your Account Number: ')
        accountnumberslist.append(accountnumber)
        balances = input('Please enter your Balance: ')
        balancelist.append(balances)
        namecount = namecount + 1
    return

def displayall():
    print ('I am inside display function')
    position =0
    #This loop, prints one name at a time from the zero position to the end. 
    while ( position < 2):
        displayone(position)
        position = position + 1
    return

def displayone(position):
    print ('Account Holder:',namelist[position])
    print ('Balance:',balancelist[position])
    return

def calculatedeposit():
      position = 0
      while (position < 2):
        depamount = int(input('Please enter the amount to deposit'))
        balancelist[position] = balancelist[position] + depamount
        position = position + 1
      return      

def calculatewithdrawal()
       position = 0
       while (position < 2):
        withmount = int(input('Please enter the amount to deposit'))
        balancelist[position] = balancelist[position] + withamount
        position = position + 1

#What does it receive. Account Number to search.
#what does it do? Searches for the Account Holder.
#what does it send back. Position of the Account Holder, if not found, -1
def searchforacct(accounttosearch):
    foundposition=-1  # assume that it is not going to be found. 
    position=0
    while (position < 2):
        if (accounttosearch==accountnumberslist[position]):
            foundposition = position
            break
        position = position + 1
    return foundposition

#This function will display the menu, collect the users response and send back
def displaymenu():
    print ('Enter P to Populate Data')
    print ('Enter S to Search for Account ')
    print ('Enter D to Deposit Amount ')
    print ('Enter W to Withdraw Amount ')
    print ('Enter E to Exit')
    choice = input('How can we help you today?:')
    return choice

print("=====================================")
print(" Welcome to Liberty City Bank ATM    ")
print("=====================================")
#main
response=''
while response!= 'E' and response!='e':
    response = displaymenu()
    if response=='P' or response=='p':
        populatelist()
    elif response=='S' or response=='s':
        accounttosearch = input('Please enter the Account Number to search:')
        foundpos = searchforacct(accounttosearch)
        if ( foundpos == -1 ):
            print ('Account not found')
        else:
            displayone(foundpos)
    elif response=='D' or response=='d':
         accounttosearch = input('Please enter the Account Number for Deposit:')
         foundpos = searchforacct(accounttosearch)
         if ( foundpos == -1 ):
            print ('Account not found')
         else:
          calculatedeposit()

    elif response=='W' or response=='w':
          accounttosearch = input('Please enter the Account Number for Withdrawal:')
          foundpos = searchforacct(accounttosearch)
          if ( foundpos == -1 ):
            print ('Account not found')
          else:
            calculatewithdrawal()

    elif response=='E' or response=='e':
        print ('Thank you for choosing Liberty City Bank!')
        print ('Have a Nice Day!')
    else:
        print ('Invalid choice. Please try again')

2 个答案:

答案 0 :(得分:0)

你的代码不会编译,在第45行添加一个:跟随你的def。第45行改变withamount to withmount。然后在第45行改变

balancelist[position] = balancelist[position] + withamount

到这个

 balancelist[position] = int(balancelist[position]) - withamount

您需要将余额列表中的字符串转换为int。您还需要从列表中减去( - )不添加(+)作为提款。

您的代码中还有一些其他错误,但这足以让您启动并运行。

答案 1 :(得分:0)

而不是查看&#39;帐户&#39;您从用户输入中找到,循环显示前2个余额列表并添加用户给定的值。