Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Chapter 5, Exercise 16: Write a program to draw a quiz score histogram. Your program should read data rom a file. Each line of the

Chapter 5, Exercise 16:

Write a program to draw a quiz score histogram. Your program should read data rom a file. Each line of the file contains a number in the range of 0-10. Your program must count the number of occurrences of each score and then draw a verticial bar chart for each possible score. For example, if 15 students each got an 8, then the height of the bar for 8 should be 15. Hint: use a list that stores the count for each possible score.

This is the code I have so far, can not get it to work, please help.

from graphics import *

def main(): print('This program analyzes a file to give a histogram') fileName = input('What is the name of your file?') list = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] fileOpen = open(fileName, 'r') data = fileOpen.readlines() for number in data: list[int(number)] += 1 win = GraphWin('Histogram', 500, 500) win.setCoords(0, -1, 50, max(list)+1) Text(Point(25, max(list) - .1), 'Histogram').draw(win) i = 4 for x in range(11): Text(Point(i, -.3), x).draw(win) Rectangle(Point(i-.5, 0), Point(i+.5, list[x])).draw(win) i = i + 4 win.getMouse() win.close() main()

In Screenshot:

image text in transcribed

Error:

image text in transcribed

I already posted this question once and got an answer that did not fix things, am kind of stuck here, please help. Thank you.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions

Question

Consider this article:...

Answered: 1 week ago