SlideShare a Scribd company logo
5/8/2017 MC303 A2_LAB 3
Creating GPA Calculatorusing
PythonProgramming Language
Nagiob Doma
ID# 6392
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():
- 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)
- 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)
-
- but1 = Button(root, text = "EXIT", command = exit).grid(row=11, column=7) #Exit button
-
- root.mainloop()
4. Test Result/ Test casesfor the program
Assignment 2 lab 3  python gpa calculator
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

More Related Content

PDF
Perl6 one-liners
PPTX
12c Mini Lesson - Invisible Columns
PDF
2013 - Benjamin Eberlei - Doctrine 2
PDF
Informatics Practices/ Information Practices Project (IP Project Class 12)
PPT
Md10 building java gu is
PPTX
PL SQL Quiz | PL SQL Examples
PPTX
Single linked list
Perl6 one-liners
12c Mini Lesson - Invisible Columns
2013 - Benjamin Eberlei - Doctrine 2
Informatics Practices/ Information Practices Project (IP Project Class 12)
Md10 building java gu is
PL SQL Quiz | PL SQL Examples
Single linked list

What's hot (20)

PPTX
Circular linked list
PPTX
Double linked list
DOC
Mc amca04919 plsql programs
PDF
Data structure and algorithm.(dsa)
PDF
Writeable CTEs: The Next Big Thing
DOCX
informatics practices practical file
PPTX
C Programming Language Part 4
DOCX
Programa en C++ ( escriba 3 números y diga cual es el mayor))
PDF
PHP for Python Developers
PPT
Doublylinklist
PDF
Closure, Higher-order function in Swift
PDF
Clang2018 class3
PDF
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
PDF
Stl algorithm-Basic types
PDF
Climbing the Abstract Syntax Tree (Forum PHP 2017)
PDF
Climbing the Abstract Syntax Tree (PHP UK 2018)
PDF
Symfony2 - extending the console component
ODT
linieaire regressie
Circular linked list
Double linked list
Mc amca04919 plsql programs
Data structure and algorithm.(dsa)
Writeable CTEs: The Next Big Thing
informatics practices practical file
C Programming Language Part 4
Programa en C++ ( escriba 3 números y diga cual es el mayor))
PHP for Python Developers
Doublylinklist
Closure, Higher-order function in Swift
Clang2018 class3
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Stl algorithm-Basic types
Climbing the Abstract Syntax Tree (Forum PHP 2017)
Climbing the Abstract Syntax Tree (PHP UK 2018)
Symfony2 - extending the console component
linieaire regressie
Ad

Similar to Assignment 2 lab 3 python gpa calculator (20)

PDF
RDataMining slides-r-programming
PDF
Program 1 (Practicing an example of function using call by referenc.pdf
PPTX
Python 03-parameters-graphics.pptx
DOCX
Produce nice outputs for graphical, tabular and textual reporting in R-Report...
PDF
analysis of data structure design programs
PDF
I really need help with this Assignment Please in C programming not .pdf
PDF
Regression and Classification with R
PDF
R basics
PPTX
Python programming workshop session 4
PPTX
Char word counter in Python with simple gui - PROJECT
PDF
The Ring programming language version 1.6 book - Part 9 of 189
PDF
Control Systems Engineering_MATLAB Experiments.pdf
PDF
Control Systems Engineering_MATLAB Experiments.pdf
DOC
Final ds record
DOCX
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
PDF
The Ring programming language version 1.7 book - Part 10 of 196
PDF
How to generate a 100+ page website using parameterisation in R
DOCX
R Language
PDF
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
PDF
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
RDataMining slides-r-programming
Program 1 (Practicing an example of function using call by referenc.pdf
Python 03-parameters-graphics.pptx
Produce nice outputs for graphical, tabular and textual reporting in R-Report...
analysis of data structure design programs
I really need help with this Assignment Please in C programming not .pdf
Regression and Classification with R
R basics
Python programming workshop session 4
Char word counter in Python with simple gui - PROJECT
The Ring programming language version 1.6 book - Part 9 of 189
Control Systems Engineering_MATLAB Experiments.pdf
Control Systems Engineering_MATLAB Experiments.pdf
Final ds record
E2 – Fundamentals, Functions & ArraysPlease refer to announcemen.docx
The Ring programming language version 1.7 book - Part 10 of 196
How to generate a 100+ page website using parameterisation in R
R Language
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Ad

Recently uploaded (20)

PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
history of c programming in notes for students .pptx
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
ai tools demonstartion for schools and inter college
PPT
Introduction Database Management System for Course Database
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
System and Network Administraation Chapter 3
PPTX
L1 - Introduction to python Backend.pptx
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Digital Strategies for Manufacturing Companies
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
history of c programming in notes for students .pptx
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Design an Analysis of Algorithms II-SECS-1021-03
ai tools demonstartion for schools and inter college
Introduction Database Management System for Course Database
Upgrade and Innovation Strategies for SAP ERP Customers
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Operating system designcfffgfgggggggvggggggggg
CHAPTER 2 - PM Management and IT Context
Softaken Excel to vCard Converter Software.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
How to Migrate SBCGlobal Email to Yahoo Easily
System and Network Administraation Chapter 3
L1 - Introduction to python Backend.pptx
Navsoft: AI-Powered Business Solutions & Custom Software Development
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
2025 Textile ERP Trends: SAP, Odoo & Oracle
Which alternative to Crystal Reports is best for small or large businesses.pdf
Digital Strategies for Manufacturing Companies

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
  • 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