In python please: A store owner keeps a record of daily cash transactions in a t
ID: 674577 • Letter: I
Question
In python please:
A store owner keeps a record of daily cash transactions in a text file. Each line contains three items: The invoice number, the cash amount, and the letter P if the amount was paid or R if it was received. Items are separated by spaces. Write a program that prompts the store owner for the amount of cash at the beginning and end of the day, and the name of the file. Your program should check whether the actual amount of cash at the end of the day equals the expected value. The output should be:
The closing balance is correct.
Or
The closing balance didn’t match.
According to the file, it should be xxxx.
Explanation / Answer
import os.path
n=0
while n==0:
file_name=raw_input("Enter name of the file with sheet: ")
if os.path.isfile(file_name):
file=open(file_name,'r')
n=1
else:
n=0
bBal=float(input("Enter balance at Begining of the day: "))
eBal=float(input("Enter balance at end of the day: "))
totalSale=eBal-bBal
total=0.0
for line in file:
m=line.split(" ")
total=total+float(m[1])
if total!=totalSale:
print "The closing balance didnot match"
print "According to file,",file_name," it must be ",totalSale
else:
print "The closing balance matches!!"
file_name=raw_input("Enter name of the file with sheet: ")
file=open(file_name,'r')
bBal=float(input("Enter balance at Begining of the day: "))
eBal=float(input("Enter balance at end of the day: "))
totalSale=eBal-bBal
total=0.0
for line in file:
m=line.split(" ")
total=total+float(m[1])
if total!=totalSale:
print "The closing balance didnot match"
print "According to file,",file_name," it must be ",totalSale
else:
print "The closing balance matches!!"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.