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

时间:2018-11-28 22:32:20

标签: python

我正在使用数组和函数为银行应用程序编写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。如何解决此问题?

2 个答案:

答案 0 :(得分:3)

在线

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

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

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

答案 1 :(得分:0)

u使用的是旧的python版本, 替换为:

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

使用'+'代替逗号

相关问题