IT45200

Untitled

May 10th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. def appendCol(fName, colName, values):
  4.     with open(fName) as fn:
  5.         lines = fn.read().splitlines()
  6.     with open(fName, "w") as fnw:
  7.         print(lines[0] + ", " + colName, file=fnw)
  8.         for x in range(1, len(lines)):
  9.             if x <= len(values):
  10.                 print(lines[x] + ", " + str(values[x-1]), file=fnw)
  11.             else:
  12.                 print(lines[x], file=fnw)
  13.                
  14. appendCol("Q4.txt","Grade",[20, 60, 75, 15])
Advertisement
Add Comment
Please, Sign In to add comment