繁体   English   中英

如何在输出中删除括号和逗号

[英]How to remove the parenthesis and a comma in the output

我正在使用数组和函数用python为银行应用程序编写程序。 这是我的代码:

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: ",(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!")

现在一切都很好,但是当我运行程序并搜索帐户时。 例如,当我搜索一个帐户时,输出将显示('name', 'account has the balance of: ', 312)而不是name account has the balance of: 312如何解决此问题?

在行中

print(NamesArray[position],"account has the balance of: ",(BalanceArray[position]))

您应该使用字符串连接来添加不同的字符串。 一种方法是这样的:

print(NamesArray[position] + " account has the balance of: " + str(BalanceArray[position])) 

您正在使用旧的python版本,请用以下代码替换您的代码行:

print(NamesArray[position] + "account has the balance of: " + (BalanceArray[position]))

使用'+'代替逗号

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM