Ask Question
27 November, 11:35

Write a program to store water usage data of 4 customers in a text file. The program asks the user to enter account number, customer type (R for residential or B for business), and number of gallons used for each of the 4 customers. Store the data in a text file named "water. txt". Overwrite old data in "water. txt" if the file already exists.

+3
Answers (1)
  1. 27 November, 11:42
    0
    with open ('water. txt','w') as file:

    i = 4

    while i > 0:

    accNo = input ('Enter Account Number: ')

    bType = input ('Enter Customer Type R or B: ')

    nGallons = input ('Enter Number of gallons: ')

    ls = ' '. join (['Account Number:', accNo,'/nType:', bType, '/nNumber Of gallons:', nGallons,'/n/n'])

    file. write (ls)

    i - = 1

    Explanation:

    The programming language used is python.

    A file water. txt is created, and a counter is initialized to ensure data is collected for all the the customers.

    A loop is created to collect the input of the four customers. The data is collected, assigned to a list and joined using the join method, to create a string of the data collected and it is written to the file.

    Using a WITH statement allows a file to automatically close.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program to store water usage data of 4 customers in a text file. The program asks the user to enter account number, customer type ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers