Question: Please follow the directions with python please and thank you! TATECS152001 MathewsSpring2019/chapterjgrsection/ rogramming home 9.8 L9-Lab Lab 9 For today's lab you are going to
TATECS152001 MathewsSpring2019/chapterjgrsection/ rogramming home 9.8 L9-Lab Lab 9 For today's lab you are going to do some string processing You are going to read a file and process the lines A single ine in the file looks like this FirstName, LastName: 1830. 20, 12904.1, -123.89, 594.814 provided you with two sample files named sample2 txt and sample1 brt You can use file read function to read and display the contents of file You can also create your own file using file write function. You are going to write 4 functions that incremenitally process the file 1 processFile() should loop over each line of the numbers to getAmount. You file calling processLine for the same and printing the result call makeUsername and getAmount passing the first last name string to makeUsername and the string of need to use string operation functions to extract the relevant information from a given line of the file Then it should return the formatted string including the results of the function calls Example processine('FirstNane, LastNane:1830.20, 12984.1, -123.89, 594.014') Returns Username: Flastna Account Balance: 15295.21 in the above example, we have passed a string to processline function, but you should pass a line of the file instead 3 makeUsername() should take a string with a first and last name separated by a single comma and return a new capitalized first letter of the first name followed by the first 6 characters of the lastName in lower case Example nakeUsername('FirstName, LastNane') Returns Flastna HINT- You can cal string spist function with different delirmiters. Notice, names are being seperated by " and further each value is 4 getAmount () should take seperated by commas " a string with floating point numbers separated by commas it should then sum each of the numbers and return the result Example getAnount ('1830.20, 12994.1, -123.89, 594.914') Returns 15295.21 ACTIVITY Additional files provided by your instructor sample2.txt and sample1.txt Download main.py 1 def processFile(filename): # Open file 3 Read line by line # print the resultof the call to proces sLine nine) pass - 4 8 def processLine(line): # Split line by colon # call makelsername with list item containing string of first and last name # call getAmount with list item containing the string holding amounts # return the formatted string username: name . Account Balance : 000000.00. # Username should be printed with 7 charactersright justified # Acount balance should print with 2 decinals left justified 10 12 13 14 15 # Hint use format string in dicsussed in 8.3. 16 17 18 def makeUserNane(user_nane): 19 # Split on comma 20 21 , pass # get first name from list # get first character from first name # make the first char upper case 23 24 25 26 27 28 29 # get last name from list # get characters 0.a5 from last name # make those characters lowercase # return the two things above concatenated pass 31 32 # split line on comma # loop through amounts # add the floating point values together pass 34 35 36 def main): 37 38 processF 39 filename-input("filename71n") ile(filenane) 40 if nameain Run your program as often as you'd like, before submitting input values in the first box, then click Run program and of Develop mode Submit mode
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
