Python read from text file III

You are given a file called studentsBase.txt. A typical line in the file looks like:

     walter melon        melon@email.msmary.edu          555-3141

There is a name, an email address, and a phone number, each separated by tabs. Write a program that reads through the file line-by-line, and for each line, capitalizes the first letter of the first and last name and adds the area code 301 to the phone number. Your program should write this to a new file called studentsBase1.txt. Here is what the first line of the new file should look like: 

    Walter Melon          melon@email.msmary.edu          301-555-3141

sudentsBase1 = open('C:/Users/ZM/Desktop/Documents/New folder/studentsBase1.txt', 'w')
students = [line.strip()
for line in open('C:/Users/ZM/Desktop/Documents/New folder/studentsBase.txt')]
studentsNew = [line.split()
for line in students]
for i in range(len(studentsNew)):
    studentsNew[i][
3] = '301-' + studentsNew[i][3]
   
for j in range(len(studentsNew[i])):
        studentsNew[i][
0] = studentsNew[i][0][:1].upper() + studentsNew[i][0][1:len(studentsNew[i][0])]
        studentsNew[i][
1] = studentsNew[i][1][:1].upper() + studentsNew[i][1][1:len(studentsNew[i][1])]
   
print(studentsNew[i][0], studentsNew[i][1], '    ', studentsNew[i][2], '      ', studentsNew[i][3], file=sudentsBase1)
sudentsBase1.close()






Коментари

Популарни постови са овог блога

Python Fan functions

Python StopWatch milliseconds

Python Accounting