簡體   English   中英

如果用戶輸入超過5的頭寸,則應該打印“找不到帳號”。

[英]If the user inputs a position over 5. It is supposed to print `The account number not found`

我正在使用python中的數組和函數編寫銀行應用程序。 我在以下行遇到麻煩, if (position>4): print("The account number not found!")這是我的代碼:

NamesArray=[]
AccountNumbersArray=[]
BalanceArray=[]
def PopulateAccounts():
    for position in range(5):
        name = input("Please enter a name: ")
        account = input("Please enter an account number: ")
        balance = input("Please enter a balance: ")
        NamesArray.append(name)
        AccountNumbersArray.append(account)
        BalanceArray.append(balance)
def SearchAccounts():
    accounttosearch = input("Please enter the account number to search: ")
    for position in range(5):
        if (accounttosearch==AccountNumbersArray[position]):
            print("Name is: " +NamesArray[position])
            print(NamesArray[position]+" account has the balance of : $" +str(BalanceArray[position]))
            break
    if (position>4):
        print("The account number not found!")


while True:
    print("**** MENU OPTIONS ****")
    print("Type P to populate accounts")
    print("Type S to search for account")
    print("Type E to exit")
    choice = input("Please enter your choice: ")
    if (choice=="P"):
        PopulateAccounts()
    elif (choice=="S"):
        SearchAccounts()
    elif (choice=="E"):
        print("Thank you for using the program.")
        print("Bye")
        break
    else:
        print("Invalid choice. Please try again!")

該代碼工作正常,除非用戶輸入的頭寸超過5。它必須打印The account number not found! 然后返回菜單。 它返回主菜單,但不打印語句。 我怎樣才能解決這個問題?

您要檢查帳戶以搜索不排名:

def SearchAccounts():
    accounttosearch = input("Please enter the account number to search: ")
    for position in range(5):
        if (accounttosearch==AccountNumbersArray[position]):
            print("Name is: " +NamesArray[position])
            print(NamesArray[position]+" account has the balance of : $" +str(BalanceArray[position]))
        break
    if (accounttosearch>4):
        print("The account number not found!")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM