A Secure and Reliable Document Management System is Essential.docx
Assignment 2 lab 3 python gpa calculator
1. 5/8/2017 MC303 A2_LAB 3
Creating GPA Calculatorusing
PythonProgramming Language
Nagiob Doma
ID# 6392
2. 1. Program Description
- This program is written using Python Programming Language with Tkinter GUI to provide for a basic window
with simple event-driven functions. The program use Python Toolkit Interfaceas a GUI to provide a simple
operating window with basic functions. The functions on the GUI window consist of Checkbox labelled with
HD’s, D’s, CR’s, UP’s and P’s in which the user will use to click on to check/mark a student’s grades. There are
total of 8 units studied annually so we have about 40 Checkbox with a “result button” and an “exit button”
displayed on the window.
- Refer below for an overall snapshot view of the executed program.
2. The Algorithm
- The program simply use basic functions, a list, and conditional statements. Also, the commands for the
Tkinter for the GUI window are also used.
When the program is executed, a window pops up displaying the units and the grades as in figure above.
When a Checkbox is clicked, the value that is assign to that checkbox is appended to an empty list. After all
the checkboxes are marked, all the values will be appended to the empty list. Thus, the empty list is then used
by a function called “calc”. This function(calc) gets the sum of the list, divide the sum with the total number of
units then use the “if statement” to categorised the results.
After all the checked button has checked, the result button is pressed. Hence, the result button activates the
“calc” function to execute the calculation and produce the result. The result is then displayed on the right side
of the GUI window.
3. Code for the Program
- #Simple GPA Calculator
- #Aurthor: Nagiob Doma (ID6392)
-
- from tkinter import *
- import math
-
- re = [] #This is an empty list that cater for all the values for the grades
-
-
- '''This are the functions that append valuse to the empty list above when a checkbox is clicked'''
- def HD():
3. - re.append(4.0)
- def D():
- re.append(3.0)
- def CR():
- re.append(2.5)
- def UP():
- re.append(2.0)
- def P():
- re.append(1.0)
-
-
-
- #This is the main function that calculates the GPA and outputs the result on the screen
-
- def calc():
- e = (sum(re))/8
-
- if 1.5 <=e<=2.4:
- label1 = Label(root, text = "The GPA result is %1.2f and the student is in %s Category" %(e,"Self
Sponsor"),font = 'Bold').grid(row=4, column=7)
-
- if 2.5 <=e<= 3.4:
- label2 = Label(root, text = "The GPA result is %1.2f and the student is in %s Category" %(e,"HECAS"),font
= 'Bold').grid(row=4, column=7)
-
-
- if 3.5 <=e<=4.0:
- label3 = Label(root, text = "The GPA result is %1.2f and the student is in %s Category" %(e,"AES"),font =
'Bold').grid(row=4, column=7)
-
- if e<1.5:
- f = e
- label3 = Label(root, text = "The Student Fails because the GPA is %1.2f" %e,font = 'Bold').grid(row=4,
column=7)
-
-
- '''TKinter commands for the User Interface'''
- root = Tk()
- root.title('GPA Calculator')
- root.geometry('900x400')
-
- label1 = Label(root, text = 'Enter the HDs, Ds, CRs, UPs and Ps', font='Italic').grid(row=0, column=7)
- '''label2 = Label(root, text = 'Unit 1').grid(row=1, column=0)'''
- label3 = Label(root, text = 'Unit 1',font='Italic').grid(row=1, column=0)
- label4 = Label(root, text = 'Unit 2',font='Italic').grid(row=2, column=0)
- label5 = Label(root, text = 'Unit 3',font='Italic').grid(row=3, column=0)
- label6 = Label(root, text = 'Unit 4',font='Italic').grid(row=4, column=0)
- label7 = Label(root, text = 'Unit 5',font='Italic').grid(row=5, column=0)
- label8 = Label(root, text = 'Unit 6',font='Italic').grid(row=6, column=0)
- label9 = Label(root, text = 'Unit 7',font='Italic').grid(row=7, column=0)
- label0 = Label(root, text = 'Unit 8',font='Italic').grid(row=8, column=0)
-
- chbut1 = Checkbutton(root, text = 'HD',command = HD).grid(row=1, column=1)
4. - chbut2 = Checkbutton(root, text = 'D',command = D).grid(row=1, column=2)
- chbut3 = Checkbutton(root, text = 'CR',command = CR).grid(row=1, column=3)
- chbut4 = Checkbutton(root, text = 'UP',command = UP).grid(row=1, column=4)
- chbut5 = Checkbutton(root, text = 'P',command = P).grid(row=1, column=5)
-
- chbut6 = Checkbutton(root, text = 'HD',command = HD).grid(row=2, column=1)
- chbut7 = Checkbutton(root, text = 'D',command = D).grid(row=2, column=2)
- chbut8 = Checkbutton(root, text = 'CR',command = CR).grid(row=2, column=3)
- chbut9 = Checkbutton(root, text = 'UP',command = UP).grid(row=2, column=4)
- chbut10 = Checkbutton(root, text = 'P',command = P).grid(row=2, column=5)
-
- chbut11 = Checkbutton(root, text = 'HD',command = HD).grid(row=3, column=1)
- chbut12 = Checkbutton(root, text = 'D',command = D).grid(row=3, column=2)
- chbut13 = Checkbutton(root, text = 'CR',command = CR).grid(row=3, column=3)
- chbut14 = Checkbutton(root, text = 'UP',command = UP).grid(row=3, column=4)
- chbut15 = Checkbutton(root, text = 'P',command = P).grid(row=3, column=5)
-
- chbut16 = Checkbutton(root, text = 'HD',command = HD).grid(row=4, column=1)
- chbut17 = Checkbutton(root, text = 'D',command = D).grid(row=4, column=2)
- chbut18 = Checkbutton(root, text = 'CR',command = CR).grid(row=4, column=3)
- chbut19 = Checkbutton(root, text = 'UP',command = UP).grid(row=4, column=4)
- chbut20 = Checkbutton(root, text = 'P',command = P).grid(row=4, column=5)
-
- chbut21 = Checkbutton(root, text = 'HD',command = HD).grid(row=5, column=1)
- chbut22 = Checkbutton(root, text = 'D',command = CR).grid(row=5, column=2)
- chbut23 = Checkbutton(root, text = 'CR',command = CR).grid(row=5, column=3)
- chbut24 = Checkbutton(root, text = 'UP',command = UP).grid(row=5, column=4)
- chbut25 = Checkbutton(root, text = 'P',command = P).grid(row=5, column=5)
-
- chbut26 = Checkbutton(root, text = 'HD',command = HD).grid(row=6, column=1)
- chbut27 = Checkbutton(root, text = 'D',command = CR).grid(row=6, column=2)
- chbut28 = Checkbutton(root, text = 'CR',command = CR).grid(row=6, column=3)
- chbut29 = Checkbutton(root, text = 'UP',command = UP).grid(row=6, column=4)
- chbut30 = Checkbutton(root, text = 'P',command = P).grid(row=6, column=5)
-
- chbut31 = Checkbutton(root, text = 'HD',command = HD).grid(row=7, column=1)
- chbut32 = Checkbutton(root, text = 'D',command = D).grid(row=7, column=2)
- chbut33 = Checkbutton(root, text = 'CR',command = CR).grid(row=7, column=3)
- chbut34= Checkbutton(root, text = 'UP',command = UP).grid(row=7, column=4)
- chbut35 = Checkbutton(root, text = 'P',command = P).grid(row=7, column=5)
-
- chbut36 = Checkbutton(root, text = 'HD',command = HD).grid(row=8, column=1)
- chbut37 = Checkbutton(root, text = 'D',command = D).grid(row=8, column=2)
- chbut38 = Checkbutton(root, text = 'CR',command = CR).grid(row=8, column=3)
- chbut39 = Checkbutton(root, text = 'UP',command = UP).grid(row=8, column=4)
- chbut40 = Checkbutton(root, text = 'P',command = P).grid(row=8, column=5)
-
-
-
-
-
- #This is the Result button that execute the calc function
- but1 = Button(root, text = "result", font= "Italic", command = calc).grid(row=10,column=7)
-
5. - but1 = Button(root, text = "EXIT", command = exit).grid(row=11, column=7) #Exit button
-
- root.mainloop()
4. Test Result/ Test casesfor the program
6.
7. References
django. (2016). The Tkinter Checkbutton Widget. Retrieved from effbot.org:
http://www.effbot.org/tkinterbook/checkbutton.htm
Tutorials Point. (2017). Retrieved from www.tutorialspoint.com:
https://www.tutorialspoint.com/python/python_gui_programming.htm