This program will be ran through a Python 3 IDE. Implement function distribution
ID: 3680402 • Letter: T
Question
This program will be ran through a Python 3 IDE.
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.
The text file that must be used is named grades, and contains this one line of code.
Here is an example of how the function should work:
>>> 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
* A side note, the formatting doesn't need a line in between. I couldn't find a way to make Chegg allow this.
Explanation / Answer
lines = "A A- C F C C B- B A A A- B B+ B+ B+ C C- B- A A A F";
print lines.count("A ")
print " students got A "
print lines.count("A-")
print " students got A- "
print lines.count("B+")
print " students got B+ "
print lines.count("B ")
print " students got B "
print lines.count("B-")
print " students got B- "
print lines.count("C ")
print " students got C "
print lines.count("C-")
print " student got C- "
print lines.count("F ")
print " students got F "
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.