Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python code please! Write a function that will read a list of ID and name combin

ID: 3800583 • Letter: P

Question

Python code please!

Write a function that will read a list of ID and name combinations from the file ids.txt. You should add all the digits of the ID and assign a team number to the person based on the remainder when divided by 6. The person’s name without ID number and the team number should be written to an output file. The function should return the number of persons assigned to each team.

Ex: 850000111 Carton, Matthew Would be assigned team number 4 and the output written to the file would be: Carton, Matthew Team: 4

There will be an unknown number of lines in the input file.

Explanation / Answer

python code:

import sys,os
import re
ll = {}
in_file = "ids.txt"
if os.path.exists(in_file):
   with open(in_file) as in_f:
   for line in in_f:
       l = re.split(' |,',line.strip())
       s = 0
       for i in range(0,len(l[0])):
           s = s + int(l[0][i])
       ll[l[0]] = s%6
for x in ll:
    print x, " is mapped to ", ll[x]

ids.txt

850000111 Carton, Matthew
342332245 sdsksn
542654122 sdsnsdd, ndnfff
124622223 sdnsdfnsd

Sample Output:

850000111 is mapped to 4
124622223 is mapped to 0
542654122 is mapped to 1
342332245 is mapped to 4