Programming with Python
Lab VII – Future Value File
Submission: FirstNameLastNameLab7.py file
Description
To complete this lab, you must download the Loans.csv file from BlackBoard. This file might become corrupted if you open it in Excel. If you would like to view the file before processing it, you should open it in a text editor like Notepad or Notepad++. If prompted, do not save the file after opening it. If your file becomes corrupted, or if you are getting an unexplained error, like ‘ValueError: could not convert string to float:’, you should try replacing the file on your machine with a fresh version downloaded from BlackBoard.
#Michael Deamer Lab 7
sourceFileName = ‘C:/Users/michael.deamer/Desktop/Python IO/Loans.csv’
destinationFileName = ‘C:/Users/michael.deamer/Desktop/Python IO/LoansWithFutureValue.csv’
Note:
The strings should represent where these files can be found on your machine.
with open(sourceFileName, ‘r’, encoding=’utf-8′) as sourceFile, open(destinationFileName, ‘a’, encoding=’utf-8′) as destinationFile:
Note:
The sourceFile is opened in read mode and the destinationFile is opened in the append mode.
line = sourceFile.readline()
print(line)
Result:
Loan ID, First Name, Last Name, Loan Principle, Annual Interest Rate, Term
Note:
The print statement in this step was to test that the code is working and should be removed.
line = sourceFile.readline()
print(line)
Result:
eca7d5db-eeff-49c1-a585-e3017bf3cb2b,Ibby,Hubbert,$485754.42,2.01%,8
Note:
Again, the print statement should be removed after we know the code is working.
line = line.replace(‘\n’, ”)
lineList = line.split(‘,’)
loanID = lineList[0]
firstName = lineList[1]
lastName = lineList[2]
loanPrinciple = lineList[3]
interest = lineList[4]
term = lineList[5]
def calculateFutureValue(p, r, t, n = 365):
pFloat = float(p.replace(‘$’, ”).replace(‘,’, ”))
rFloat = float(r.replace(‘%’, ”))*.01
tFloat = float(t)
a = pFloat*(1 + rFloat/n)**(n*tFloat)
return a
fV = calculateFutureValue(loanPrinciple, interest, term)
while line != ”:
Note:
The condition is that the loop should repeat until the line variable equals an empty string. This works because there is no empty line in our source csv. The first empty line indicates that there is no more data.
The lines of code from Steps 7 to 11 should appear inside this while loop.
line =sourceFile.readline()
destinationFile.write(‘Loan ID, First Name, Last Name, Loan Principle, Annual Interest Rate, Term, Future Value\n’)
destinationFile.write(loanID+’,’+firstName+’,’+lastName+’,’+loanPrinciple+’,’+interest+’,’+term+’,’+str(fV)+’\n’)
Note:
This line of code should appear as the second to last line in the while loop
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more
Recent Comments