Respuesta :
Answer:
The program for this question can be given as:
Program:
def main():
f= open("water.txt","w+")
for i in range(4):
f.write(input('Enter account number:\r\n'))
f.write(input('Enter R for residential,B for business:\r\n'))
f.write(input('Enter number of gallons used:\r\n'))
f.close()
if __name__== "__main__":
main()
Output:
Enter account number:12
Enter R for residential,B for business:R
Enter number of gallons used:12345
Enter account number:13
Enter R for residential,B for business:B
Enter number of gallons used:8906
Enter account number:11
Enter R for residential,B for business:B
Enter number of gallons used:56789
Enter account number:10
Enter R for residential,B for business:R
Enter number of gallons used:12348
create a file water.text
12R12345
13B8906
11B56789
10R12348
Explanation:
In the above python program firstly we define the main function in this function we use the f.open() function. This function helps to open a file, and returns its values as a file object. In this function, we pass the file name and mode that is "water.txt" and "w+". The "w+" mode is used for writing mode and If the file does not exist then it will create a new file and "+" is used for reading and writing (updating) the file. Then we will use the input() function. This function helps to take input from the user. then we will close the file and end the main function.