Question

Write a python program that executes the following conditions: A store owner keeps a record of...

Write a python program that executes the following conditions:
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.

Example,
Enter the beginning cash balance: 35
Enter the ending cash balance: 70
Enter the file name: balance.txt
The closing balance does not match. It Should be 60.00

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def main():
    initial = float(input('Enter the beginning cash balance: '))
    final = float(input('Enter the ending cash balance: '))
    filename = input('Enter the file name: ')
    total = 0
    with open(filename, 'r') as f:
        for line in f:
            words = line.strip().split()
            total += float(words[1])
    total += initial
    if total == final:
        print('The closing balance does match.')
    else:
        print('The closing balance does not match. It Should be %.2f' % total)

main()

Enter the ending cash balance: i balance.txt The closing balance does not match. It Should be 60.00 Process finished with e x

Add a comment
Know the answer?
Add Answer to:
Write a python program that executes the following conditions: A store owner keeps a record of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Starting out with python 4th edition Write program that lets the user enter in a file...

    Starting out with python 4th edition Write program that lets the user enter in a file name (numbers.txt) to read, keeps a running total of how many numbers are in the file, calculates and prints the average of all the numbers in the file. This must use a while loop that ends when end of file is reached. This program should include FileNotFoundError and ValueError exception handling. Sample output: Enter file name: numbers.txt There were 20 numbers in the file....

  • Looking for code in MATLAB: A store owner asks you to write a program for use...

    Looking for code in MATLAB: A store owner asks you to write a program for use in the checkout process. The program should: Prompt the user to enter the cost of the first item Continue to prompt for additional items, until the user enters 0 Display the total. Prompt for the dollar amount the customer submits as payment. Display the change due.

  • Write a Python program which prompts the user for a file name then a sentence. Display...

    Write a Python program which prompts the user for a file name then a sentence. Display the number of characters in the sentence and save the sentence to the file name. If the file already exists, ask the user if the file should be overwritten.

  • Write a program to keep track of the inventory of grocery store. Write a test program...

    Write a program to keep track of the inventory of grocery store. Write a test program that prompts the user to enter how many items of inventory the store has. After that enter item name, quantity and price of each item in three different arrays called Itemname, Quantity and Price. Than calculate the Total=Quantity*Price of items in store and FinalTotal of all the items and print in following exact format using array: Sample run of program: Enter number of items...

  • Write a Python program to create userids: You work for a small company that keeps the...

    Write a Python program to create userids: You work for a small company that keeps the following information about its clients: • first name • last name • a user code assigned by your company. The information is stored in a file clients.txt with the information for each client on one line (last name first), with commas between the parts. In the clients.txt file is: Jones, Sally,00345 Lin,Nenya,00548 Fule,A,00000 Your job is to create a program assign usernames for a...

  • write a python program that prompts the user for a name of a text file, opens...

    write a python program that prompts the user for a name of a text file, opens that file for reading , and tracks the unique words in a file and counts how many times they occur in the file. Your program should output the unique words and how often they occur in alphabetical order. Negative testing for a file that does not exist and an empty file should be implemented.

  • in python Write a program that keeps a dictionary in which both keys and values are...

    in python Write a program that keeps a dictionary in which both keys and values are strings—names of students and their course grades. Prompt the user of the program to add or remove students, to modify grades, or to print all grades. The printout should be sorted by name and formatted like this: Carl: B- Joe: C Sarah: A Francine: A

  • PYTHON CODE First Code: Write a program that uses a text file to store the daysand...

    PYTHON CODE First Code: Write a program that uses a text file to store the daysand hours that a user worked in a week. The program should begin by prompting for the number of days worked in the week. It should continue with a loop for input of the days and hours and for writing these to the file, each on its own line. Sample Output (inputs shown in boldface) How many days did you work this week? 5 Enter...

  • Please write comments with the program. Python programming!! Part III - write student data In this...

    Please write comments with the program. Python programming!! Part III - write student data In this part the program should create a .csv file and fill it with generated student information. The program should: Ask the user for a name for the .csv file (use your own name for the exercise) Create the .csv file with columns named - ID, first-name, GPA Based on the information received in part I, generate and fill students information in the CSV file Tell...

  • Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a...

    Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a file called Numbers.txt in your the same folder as your Python program. This file should contain a list on floating point numbers, one on each line. The number should be greater than zero but less than one million. Your program should read the following and display: The number of numbers in the file (i.e. count them) (counter) The maximum number in the file (maximum)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT