Question: #5 Charge Account Validation Save the file as ch7_ex2.py Write a program that reads the account numbers from a file into a list. The user

#5 Charge Account Validation Save the file as ch7_ex2.py Write a program that reads the account numbers from a file into a list. The user is asked to enter a charge account number, and the program should determine if the number is valid by searching the list. If the number is in the list, the program should display a message indicating the number is valid. If the number is not in the list, the program should show the number is invalid. The program must: Declare the variable test_acct inside the main function and initialize it as an empty string. Include a try block inside the main function that handles IOError exceptions. Open the text file for reading. Read all the account numbers into a list. Close the file. Reference the user-entered account number and display whether or not the account is valid. Test the program using the following text file (download from BlackBoard assignment page): 7-2-accounts.txt The output should look like these invalid and valid entries: Enter the account number to be validated: 1234567 Account number 1234567 is not valid. Enter the account number to be validated: 5946311 Account number 5946311 is valid.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!