Drawing bars with a survey package
Write code · Medium · §4.3, §7.2, §12.5 Packages
There is a package, survey, that counts survey responses and shows them as bars. Count the responses with tally() from survey.tally, make each bar with bar() from survey.chart, and print one choice per line, like B ###. Print the lines in the same order as the dictionary that tally() returns. Grading also runs the code with different answers and different contents of the package files.
Starter code
answers = ["B", "A", "B", "C", "B", "A"]File survey/__init__.py
File survey/tally.py
def tally(answers):
counts = {}
for a in answers:
if a in counts:
counts[a] += 1
else:
counts[a] = 1
return countsFile survey/chart.py
def bar(n):
return "#" * nSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.