Python Help... Implement function distribution() that takes as input the name of a file (as a string). This one-line file will contain letter grades separated by blanks. Your function should print the distribution of grades, as shown. Hints: Use the print format() module to print results (1 student got ) ( grades student got) and remember to save the function and the text file in the same directory. def distribution(filename): ‘Put in docstring’ # get file content infile = ________________# ______________ content = ______________# ______________ infile__________________# ______________ # split content into a list of grades grades = _______________________# ______________ # for every grade, print the number of times it occurs if any for grade in ______________________________ # _______________ num = ___________________# _______________ if _______________# _______________ if __________# _______________ print_________________# _______________ else: print________________________________# _______________ Result of running the function. >>> distribution('Grades.txt') 6 students got A 2 students got A- 3 students got B+ 2 students got B 2 students got B- 4 students got C 1 student got C- 2 students got F
Python Help...
Implement function distribution() that takes as input the name of a file (as a string). This one-line file will contain letter grades separated by blanks. Your function should print the distribution of grades, as shown. Hints: Use the print format() module to print results (1 student got ) ( grades student got) and
remember to save the function and the text file in the same directory.
def distribution(filename):
‘Put in docstring’
# get file content
infile = ________________# ______________
content = ______________# ______________
infile__________________# ______________
# split content into a list of grades
grades = _______________________# ______________
# for every grade, print the number of times it occurs if any
for grade in ______________________________ # _______________
num = ___________________# _______________
if _______________# _______________
if __________# _______________
print_________________# _______________
else:
print________________________________# _______________
Result of running the function.
>>> distribution('Grades.txt')
6 students got A
2 students got A-
3 students got B+
2 students got B
2 students got B-
4 students got C
1 student got C-
2 students got F
Trending now
This is a popular solution!
Step by step
Solved in 2 steps