Computer Science > QUESTIONS & ANSWERS > Broward College COMPUTER S COMPUTER S 575705 Read in and store the data from the file called 'Jan (All)
Answered by Expert Tutors #File: January.txt 21728392 1200.56 19.18,29.15,78.75,212.10 100,20,410.29 #File: main.py input_file_name = "January.txt" output_file_name ... = "JanuarySatement.txt" name = input("Enter name: ") age = int(input("Enter age: ")) username = name.lower().split()[0][:1]+ name.lower().split()[1][:5]+str(age) f = open(input_file_name, "r", ) #read file line = f.readlines() #read all lines accountNumber = (line[0][:3] + "-"+ line[0][3:5] + "-" +line[0][-4:]).strip() #slice the string from first line (first line for account number) beginBalance = float(line[1]) #read second line for begin balance totalWithdrawals = sum(float(x) for x in line[2].split(',')) #sum all from thirds line totalDeposits = sum(float(x) for x in line[3].split(',')) #sum all from fourth line endBalance = beginBalance + totalDeposits - totalWithdrawals print ( "{:30s} {:10s}".format("Username: ", username) .center(80) ) print ( "{:30s} {:10s}".format("Account Number: ", accountNumber) .center(80) ) print ( "{:30s} ${:10.2f}".format("Beginning Balance: ", beginBalance) .center(80) ) print ( "{:30s} ${:10.2f}".format("Total withdraws: ", totalWithdrawals) .center(80) ) print ( "{:30s} ${:10.2f}".format("Total deposits: ", totalDeposits) .center(80) ) print ( "{:30s} ${:10.2f}".format("Ending balance: ", endBalance) .center(80) ) f = open(output_file_name, "w") f.write( "{} {}".format("Username: ", username) ) f.write( "\n{} {}".format("Account Number: ", accountNumber) ) f.write( "\n{} ${:10.2f}".format("Beginning Balance: ", beginBalance) ) f.write( "\n{} ${:10.2f}".format("Total withdraws: ", totalWithdrawals) ) f.write( "\n{} ${:10.2f}".format("Total deposits: ", totalDeposits)) f.write( "\n{} ${:10.2f}".format("Ending balance: ", endBalance)) f.close() print("File {} created successfully".format(output_file_name)) #File: JanuarySatement.txt (generated by program) Username: mjordo37 Beginning Balance: $ 1200.56 Total withdraws: $ 339.18 Total deposits: $ 530.29 Ending balance: $ 1391.67 #File: JanuaryStatement.txt (generate by program) Username: mjordo37 Account Number: 217-28-392 Beginning Balance: $ 1200.56 Total withdraws: $ 339.18 Total deposits: $ 530.29 Ending balance: $ 1391.67 Step-by-step explanation comment if you have any doubts/questions. output: string_file.png [Show More]
Last updated: 3 years ago
Preview 1 out of 2 pages
Buy this document to get the full access instantly
Instant Download Access after purchase
Buy NowInstant download
We Accept:
Can't find what you want? Try our AI powered Search
Connected school, study & course
About the document
Uploaded On
Mar 15, 2021
Number of pages
2
Written in
All
This document has been written for:
Uploaded
Mar 15, 2021
Downloads
0
Views
76
Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Scholarfriends · High quality services·