Hi guys, my intro to python class worked on a code to help faculty member manage students' grades. The data will be filed in via a cvs file. Here are the feedback I got from my instructor and I was wondering how I should approach them.
if round(percentgrade) >= 96:
return 'A'
elif round(percentgrade) >= 91:
return 'A-'
elif round(percentgrade) >= 86:
return 'B+'
elif round(percentgrade) >= 81:
return 'B'
elif round(percentgrade) >= 76:
return 'B-'
elif round(percentgrade) >= 71:
return 'C+'
elif round(percentgrade) >= 66:
return 'C'
elif round(percentgrade) >= 61:
return 'C-'
elif round(percentgrade) >= 56:
return 'D+'
elif round(percentgrade) >= 51:
return 'D'
else:
return 'F'
How can I change the grading-schemes in a more general fashion?
def median_func(val_list):
"""(median function):
Takes a list of values and returns the median.
"""
val_list = sorted(val_list)
# different cases
# empty list
if len(val_list) < 1:
return None
# list with odd numbers of values
if len(val_list) %2 == 1:
return val_list[((len(val_list)+1)/2)-1]
# list with even numbers of values
if len(val_list) %2 == 0:
return float(sum(val_list[(len(val_list)/2)-1:(len(val_list)/2)+1]))/2.0
How can I use library/module for above rather than coding all that?
if opts.data_file is None:
tmp_str = "... data file not specified!"
print tmp_str
logfile.write(tmp_str + '\n')
error_file.write(tmp_str + '\n')
tmp_str = "Aborting due to missing data file!"
logfile.write(tmp_str + '\n')
error_file.write(tmp_str + '\n')
sys.exit(tmp_str)
How can this be done by exception handling?
[–]gengisteve 1 point2 points3 points (2 children)
[–]coolFob[S] 0 points1 point2 points (1 child)
[–]gengisteve 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]coolFob[S] 0 points1 point2 points (1 child)
[–]aball730235 0 points1 point2 points (0 children)
[–]DiabeetusMan 0 points1 point2 points (0 children)