64.5k views
2 votes
Write a program that reads the content of a file named charge_account.txt, which holds a list of charge account numbers which are 7 digit values, then asks the user to enter a charge account number. The program should then determine whether the number is in the list or not. It should then display a message indicating whether or not it is there.

User Dudar
by
7.5k points

1 Answer

4 votes

Answer:

Here's an example of how you could write a program in Python that reads the contents of a file named "charge_account.txt" and checks if a given charge account number is in the list:

Step-by-step explanation:

# Open the file for reading

with open("charge_account.txt", "r") as file:

# Read all the lines in the file

charge_accounts = [line.strip() for line in file.readlines()]

# Ask the user to enter a charge account number

charge_account = input("Enter a charge account number: ")

# Check if the charge account number is in the list

if charge_account in charge_accounts:

print("The charge account number is in the list.")

else:

print("The charge account number is not in the list.")

User Dossani
by
8.4k points