After writing the program of Exercise 17.7, write a simple program to create some test data for checking out the program. Use the following sample account data:

Master file
Account number Name Balance
100 Alan Jones 348.17
300 Mary Smith 27.19
500 Sam Sharp 0.00
700 Suzy Green -14.22
Transaction file
Account number Transaction amount
100 27.14
300 62.11
400 100.56
900 82.17


Run the program of Exercise 17.7 using the files of test data created in Exercise 17.8. Print the new master file. Check that the accounts have been updated correctly.

You are welcome to ask questions about how to proceed, or post code to help correction of logic or syntax.

To create test data for checking the program in Exercise 17.7, you can write a simple program that creates two text files: one for the master file and one for the transaction file.

Here's an example of how you can create the test data in Python:

```python
master_data = [
{"account_number": 100, "name": "Alan Jones", "balance": 348.17},
{"account_number": 300, "name": "Mary Smith", "balance": 27.19},
{"account_number": 500, "name": "Sam Sharp", "balance": 0.00},
{"account_number": 700, "name": "Suzy Green", "balance": -14.22}
]

transaction_data = [
{"account_number": 100, "transaction_amount": 27.14},
{"account_number": 300, "transaction_amount": 62.11},
{"account_number": 400, "transaction_amount": 100.56},
{"account_number": 900, "transaction_amount": 82.17}
]

# Creating the master file
with open("master_file.txt", "w") as file:
file.write("Account number\tName\tBalance\n")
for account in master_data:
file.write(f"{account['account_number']}\t{account['name']}\t{account['balance']}\n")

# Creating the transaction file
with open("transaction_file.txt", "w") as file:
file.write("Account number\tTransaction amount\n")
for transaction in transaction_data:
file.write(f"{transaction['account_number']}\t{transaction['transaction_amount']}\n")
```

This code will create two text files: "master_file.txt" and "transaction_file.txt" which contain the test data provided.

To run the program from Exercise 17.7 using these test data files and print the new master file with the updated account balances, you can follow these steps:

1. Read the master file and transaction file using file input/output operations in Python.
2. Iterate through the transaction file and update the account balances in the master file according to the transactions.
3. Write the updated account balances to a new master file.
4. Print the new master file.

Here's an example of how you can achieve this:

```python
# Open the master file and transaction file
with open("master_file.txt", "r") as master_file, open("transaction_file.txt", "r") as transaction_file:
# Read the contents of the files
master_data = master_file.readlines()
transaction_data = transaction_file.readlines()

# Create a dictionary to store the updated account balances
updated_balances = {}

# Process the transactions and update the balances
for transaction in transaction_data[1:]: # Skip the header line
account_number, transaction_amount = transaction.strip().split("\t")
account_number = int(account_number)
transaction_amount = float(transaction_amount)

# Update the balance in the dictionary
if account_number in updated_balances:
updated_balances[account_number] += transaction_amount
else:
updated_balances[account_number] = transaction_amount

# Update the account balances in the master data
updated_master_data = [master_data[0]] # Add the header line

for account in master_data[1:]:
account_number, name, balance = account.strip().split("\t")
account_number = int(account_number)
balance = float(balance)

# Update the balance if there are transactions for this account
if account_number in updated_balances:
balance += updated_balances[account_number]

# Append the updated account to the new master data list
updated_master_data.append(f"{account_number}\t{name}\t{balance}\n")

# Write the updated master data to a new file
with open("updated_master_file.txt", "w") as new_master_file:
new_master_file.writelines(updated_master_data)

# Print the new master file
with open("updated_master_file.txt", "r") as new_master_file:
print(new_master_file.read())
```

This code will process the transactions from the transaction file and update the account balances in the master file. The updated master file will be printed at the end.