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.t
...
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]