Answer:
See explaination for code
Step-by-step explanation:
# Take user input
opening_balance = float(input('Enter the opening cash balance: '))
closing_balance = float(input('Enter the closing cash balance: '))
filename = input('Enter the file name: ')
# Open file to read
fileread = open(filename, 'r')
# Set file_balance to opening balance
file_balance = opening_balance
# Iterate over file
# Split line to get data from it
for line in fileread.readlines():
data = line.rstrip().split()
# Add payment is R means Received else subtract
if data[2] == "R":
file_balance += float(data[1])
else:
file_balance -= float(data[1])
# Check if equal and print message accordingly
if file_balance == closing_balance:
print('The closing balance is correct')
else:
print('The closing balance didn\'t match.\\According to the file, it should be', file_balance)
Please kindly check attachment for screenshot and output.