Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # U05_Ex15_ExamBarGraph.py
- #
- # Author: Joseph Cloud
- # Course: Coding for OOP
- # Section: A3
- # Date: 13 Oct 2017
- # IDE: PyCharm Community Edition
- #
- # Assignment Info
- # Exercise: 15
- # Source: Python Programming
- # Chapter: 5
- #
- # Program Description
- # This program displays a graph of students' exam scores
- # Algorithm (pseudocode)
- # Introduction window
- # Get filename
- # Open file for reading
- # Read file and split to get names and grades of students
- # Close the file
- # Create window for the graph
- # Loop creating and drawing text and rectangles based off of list info
- # Wait for mouse click to close the window
- import re
- from tkinter.filedialog import askopenfilename
- from graphics import *
- def main():
- window = GraphWin('Introduction', 600, 150)
- Text(Point(300,75), 'This Program Returns a Graph of Students Names and Their Corresponding Grades').draw(window)
- window.getMouse()
- window.close()
- fileName = askopenfilename()
- file = open(fileName, 'r')
- numStud = file.readline()
- delimiters = " ", "\n"
- splitPattern = '|'.join(map(re.escape, delimiters))
- stuGrad = re.split(splitPattern, file.read())
- file.close()
- window = GraphWin('Exam Scores', 200, len(stuGrad)*20)
- Text(Point(100, len(stuGrad)*20-10), 'Exam Scores Bar Graph').draw(window)
- for i in range(numStud):
- Text(Point(35, 40*i-20), '{0:>10}'.format(stuGrad[i*2])).draw(window)
- Rectangle(Point(80, 40*i-15), Point(80+int(stuGrad[1+i*2]), 40*i-25)).draw(window)
- window.getMouse()
- window.close()
- main()
Add Comment
Please, Sign In to add comment