LTC Spamm needs to send an email inviting high-acheiving cadets from various maj
ID: 3884951 • Letter: L
Question
LTC Spamm needs to send an email inviting high-acheiving cadets from various majors to a celebration of academic excellence. She has exported data on 2,000 cadets to a comma-separated-values (.csv) file named MOCK DATA.csv. She would like to extract the email addresses of all qualified cadets from the file, but, ironically, she does not know how to code. She has asked for your help. Write a function named build_acheiver_distro () that takes in three parameters, the filename of the csv as a string, the "major_code" as a string and the GPA_threshold as a float. Your function will return a distro list of email addresses in the form of a string of every email address belonging to cadet of the appropriate major whose GPA is greater than or equal to the GPA_threshold. All but the final email address should be followed by a semicolon and a space, i.e. 'cadet.x@usma.edu: cadet.y@usma.edu: cadet.z@usma.edu'Explanation / Answer
'''
Assuming each line in the file as follows:
name, major, gpa, e-mail
'''
def build_acheiver_distro(filename,major,gpa_threshold):
emails = []
file = open(filename,"r")
for line in file:
list1 = line.split(',')
if major in list1:
if float(list1[2]) >= gpa_threshold:
emails.append(list1[3])
return emails
print(build_acheiver_distro("file5.txt","CSC1",3.0))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.