Guest User

Untitled

a guest
Oct 18th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. # U05_Ex15_ExamBarGraph.py
  2. #
  3. # Author: Joseph Cloud
  4. # Course: Coding for OOP
  5. # Section: A3
  6. # Date: 13 Oct 2017
  7. # IDE: PyCharm Community Edition
  8. #
  9. # Assignment Info
  10. # Exercise: 15
  11. # Source: Python Programming
  12. # Chapter: 5
  13. #
  14. # Program Description
  15. # This program displays a graph of students' exam scores
  16. # Algorithm (pseudocode)
  17. # Introduction window
  18. # Get filename
  19. # Open file for reading
  20. # Read file and split to get names and grades of students
  21. # Close the file
  22. # Create window for the graph
  23. # Loop creating and drawing text and rectangles based off of list info
  24. # Wait for mouse click to close the window
  25.  
  26. import re
  27. from tkinter.filedialog import askopenfilename
  28. from graphics import *
  29.  
  30. def main():
  31. window = GraphWin('Introduction', 600, 150)
  32. Text(Point(300,75), 'This Program Returns a Graph of Students Names and Their Corresponding Grades').draw(window)
  33. window.getMouse()
  34. window.close()
  35.  
  36. fileName = askopenfilename()
  37.  
  38. file = open(fileName, 'r')
  39.  
  40. numStud = file.readline()
  41.  
  42. delimiters = " ", "\n"
  43. splitPattern = '|'.join(map(re.escape, delimiters))
  44. stuGrad = re.split(splitPattern, file.read())
  45.  
  46. file.close()
  47.  
  48. window = GraphWin('Exam Scores', 200, len(stuGrad)*20)
  49.  
  50. Text(Point(100, len(stuGrad)*20-10), 'Exam Scores Bar Graph').draw(window)
  51.  
  52. for i in range(numStud):
  53. Text(Point(35, 40*i-20), '{0:>10}'.format(stuGrad[i*2])).draw(window)
  54. Rectangle(Point(80, 40*i-15), Point(80+int(stuGrad[1+i*2]), 40*i-25)).draw(window)
  55.  
  56. window.getMouse()
  57. window.close()
  58. main()
Add Comment
Please, Sign In to add comment