简体   繁体   中英

How to remove the parenthesis and a comma in the output

I am writing a program in python for a banking application using arrays and functions. Here's my code:

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!")

Everything is fine now, but when I run the program and search for an account. For example, when I search an account the output shows ('name', 'account has the balance of: ', 312) instead of name account has the balance of: 312 How do I fix this?

In the line

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

you should use string concatenation to add the different strings. One way to do this would be like this:

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

u are using old python version, replace your line with this :

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

use ' + ' instead of comma

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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