154k views
1 vote
A manager keeps a record of daily each transaction in input.txt. Each line contains three items: The invoice number, the cash amount, and the letter P refers to the amount that has been paid or R if it was received. Items are separated by spaces. Write a program that prompts the manager to provide the opening cash balance, the closing cash balance, and the file name (i.e., input.txt) that the manager wants to read. Then, your program should check whether the closing cash balance equals the expected value after processing input.txt.

1 Answer

2 votes

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.

A manager keeps a record of daily each transaction in input.txt. Each line contains-example-1
A manager keeps a record of daily each transaction in input.txt. Each line contains-example-2
A manager keeps a record of daily each transaction in input.txt. Each line contains-example-3
User Apdastous
by
6.1k points