Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Computing Fundamental

Submission date 29/01/2024 Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Nguyen Duy Hoang Student ID BH01754

Class COM109.02 Assessor name Nguyen Thanh Trieu

Student declaration

I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that
making a false declaration is a form of malpractice.

Student’s signature Hoang

Grading grid

P1 P2 P3 M1 M2 M3 D1 D2 D3

1
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Lecturer Signature:

2
CONTENTS
I. INTRODUCTION ..................................................................................................................................................... 2
II. REQUEST ................................................................................................................................................................ 2
III. TASK....................................................................................................................................................................... 2
P1: Provide a definition of thedata type that you use for the variables. .................................................................... 2
1) Variables ........................................................................................................................................................ 2
2) Data types. ..................................................................................................................................................... 3
3) Explains the selected data types. ................................................................................................................... 3
P2. Explain the error handling process. ..................................................................................................................... 4
1.1. Describe the types of errors that the program might encounter................................................................. 4
2. Outline the steps involved in handling errors using a try-except block. ........................................................... 6
P3. Determine the steps taken from writing code to execution. ................................................................................ 7
1. List the steps involved in writing and executing the program. .......................................................................... 7
2. Briefly explain the purpose of each step. .......................................................................................................... 7
3. Identify the tools and resources used for writing and executing the program. .................................................. 9
M1. Compare the advantage and disadvantage of variables type. ........................................................................... 10
M2. Examine how the debugging process can be used to help develop more secure, robust applications. ............ 12
M3. Analyse the process of writing code, including the potential challenges faced. .............................................. 14
1. Analyze the coding process. ........................................................................................................................ 14
IV. CONCLUSION ..................................................................................................................................................... 15
V. REFERENCE ......................................................................................................................................................... 16

1
I. INTRODUCTION
In the education system, calculating a student's GPA is an important aspect of measuring and
evaluating their understanding and academic progress. This need is not only of a management and
evaluation nature, but also as a decision support tool in the educational process. Calculating GPA requires
technical and precise calculations, focusing on assigning weights to different courses and modules. These
helps create a number that describes the student's success in their studies. Average score is not just a
number, but an expression of effort, investment and ability to absorb knowledge. Through the process of
calculating GPA, teachers and educational administrators have the ability to monitor student growth each
semester, and provide important feedback to assist them in perfecting their skills and knowledge awake. In
addition, GPA is also an important deciding factor when students prepare to enter the labor market, where
success and career opportunities are often evaluated based on academic performance.

In this assignment, I need to calculate my grade point average (GPA) in different courses. The system
requirement is to write a Python program that can perform this task. The program needs to define a
function to calculate the average grade based on a list of grades and their corresponding number of credits.

II. REQUEST
1. The GPA calculator program must meet the following requirements:
2. It must be able to store the student's name and grades in a list.
3. It must be able to calculate the GPA using a function.
4. It must be able to handle errors and invalid input.
5. It must be able to print the results to a text file.

III. TASK

P1: Provide a definition of thedata type that you use for the variables.
1) Variables
Identify the variables used in the program.

2
1. tin_chi_st: A list containing the credit hours corresponding to each course.
2. diem: A list containing the grades corresponding to each course.
3. name: The name of the student.
4. full_name: A variable containing the full name of the student, input from the user.
5. tin_chi_1, tin_chi_2, tin_chi_3: Variables containing the credit hours for each course, input from
the user.
6. diem_1, diem_2, diem_3: Variables containing the grades for each course, input from the user.
7. tin_chi: A list containing the credit hours for all courses.
8. diem_st: A list containing the grades for all courses
9. average_point: A variable containing the cumulative average grade of the student after calculation.
10. file: A variable representing the 'data/point.txt' file opened for writing the grade information.

2) Data types.
Specify the data type for each variable.

1. full_name: (String) is a very commonly used data type in Python, a word, a piece of text are all
string types.
2. diem_1,diem_2,diem_3: (Float) is a data type, used in Python to represent zeros in integer form or
in other words, decimal form.
3. tin_chi: (Integer) is a data type, used in Python to represent integers.
4. average_point: The average score includes both integers and decimals, so choose (float)
5. diem_st: (List) is a data type that allows storing many different data types and accessing elements
within it through the position of that element in the list.

3) Explains the selected data types.


Briefly explain the reason for choosing the selected data type

1. Data type (int) is an integer type, used to represent integers without decimal parts. A variable of type
(int) can contain a value that is a positive integer, negative integer, or zero.

3
2. In Python, the data type (float) is used to represent real numbers (numbers with decimal parts). A
variable of type (float) can contain a value that is a positive real number, a negative real number, or a
zero real number.

3. (List) is a proprietary flexible data type in Python. (List) is officially an ordered sequence of some data
written with square brackets ([]) and commas (,).

4. (str) Names are characters so they are represented as strings so we use them for the name parameter.

P2. Explain the error handling process.


Describe the types of errors that the program might encounter.
Common errors when writing programs.

When written, programs have certain errors that the writer needs to fix so that the program can
operate smoothly without any problems.

1. File not found error:

4
File 'data/point.txt' not found error or if there is a problem with access to the file, opening in
function 'show_point_of_student' may cause a FileNotFoundError.

2. Error handling when entering data:

In the user input section, you should handle additional errors to ensure that the user enters valid
values (for example, do not enter a string for signal indication).

3. Missing punctuation error when writing:

When writing programs, we often forget parentheses or commas, which can also cause program
errors.

4. Calculation error:

When writing programs, calculation formulas are also extremely important. When the formula is
wrong, our results will be wrong.

5. Line error:

When writing a program, two lines with different lengths also cause the program to misunderstand
and cause errors.

6. Runtime error:

5
Runtime error is a type of error that occurs during program execution. Execution errors are also
called exceptions. For example, in the program you accidentally perform division by 0, or retrieve a file
that does not exist on the drive.

7. Syntax error:

Type of error that occurs due to writing code that does not comply with the rules of the language.

2. Outline the steps involved in handling errors using a try-except block.


Error handling in Python is typically done using (try...except) blocks.

1. (Try) block:

The (try) block is used to surround source code that you suspect may generate errors.

2. (Except) block:

The except block contains code to enable error handling.

3. (Else) block:

If no exception occurs in the try block, the else block will be executed. This block is optional.

The else block is useful in separating code that might cause an exception from code that runs only
if no exception occurs.

4. (Finally) block:

The finally block is always executed regardless of whether an exception occurs or not. It is often
used to clean up code, such as closing files or freeing resources.

The finally block is optional, but if present, it ensures that the specified code will be executed in all
cases.

6
P3. Determine the steps taken from writing code to execution.
1. List the steps involved in writing and executing the program.

1. Install Python

Before you start writing Python code, you need to install Python on your computer. This can be
done by visiting the official Python website and downloading the latest version for your operating
system. Once downloaded, follow the instructions to install Python.

2. Open the Development Environment (IDE)

Python has many powerful development environments for you to program in, and some of them
have user-friendly interfaces that make it easy to write and run Python code. PyCharm is an IDE
developed by JetBrains, specifically designed for Python and has a free version.

3. Create a New Python File:

Open your chosen text editor or IDE and create a new Python file with a .py extension. This is where you
will write your Python code.

4. Write a Program.

Write the program that posts the request.

5. Run the Program.

Write a python program then save it to a file. Use correct syntax and indentation, as Python relies on
indentation to identify blocks of code.

6. Testing and debugging.

Optimize the program and find and fix errors that cause the program to not run or run incorrectly
as expected.

2. Briefly explain the purpose of each step.


1. Function point_avg_student(information_chi_st, score):

Purpose: Calculate the cumulative average score based on the number of credits and scores of the
subjects.

7
2. Function show_point_of_student(name, point):

Purpose: Display information about students and cumulative GPA on the console screen, as well as
write information to a text file.

3. Enter information from users:

Purpose: Get information such as student name, number of credits and grades from the user to
calculate cumulative average.

4. Use list to store information:

Purpose: Organize information about credits and scores of subjects into lists for easy management.

5. Calculate cumulative average score:

Purpose: Use the point_avg_student function to calculate the cumulative average score from
information about the number of credits and scores of the subjects.

8
6. Display and save cumulative average score:

Purpose: Display information and calculation results on the console screen, as well as write to a text
file.

3. Identify the tools and resources used for writing and executing the program.
1. Python programming language:

Purpose: Python is used as the main programming language to write programs.

Resources: Python is a popular and powerful programming language, commonly used in many
fields.

2. Development environment (IDE) or compiler:

Purpose: To write and run Python source code.

Resources: Can use IDEs such as PyCharm, VSCode, or the default Python compiler to write and
execute programs.

3. Text file to save source code:

Purpose: Stores program source code.

Resource: A text file, such as .py to store Python source code.

4. Input/Output tool:

Purpose: Enter information from the user and display results on the screen.

Resources: Input function to receive data from the user and print function to display results.

5. File processing tools:

9
Purpose: Record information to a text file.

Resources: Use the with open('filename', 'w') as file statement to open the file and write
information to it.

6. Error handling:

Purpose: Handle and report errors if any.

Resources: Use try, except statements to catch and handle types of errors that may occur.

7. Python standard library:

Purpose: Provides utility functions and methods such as sum and len.

Resources: Functions in the standard library help perform tasks such as calculating the sum and
length of a list.

After returning the results

M1. Compare the advantage and disadvantage of variables type.


After writing a program to calculate students' cumulative average score, they need to compare the
advantages and disadvantages of variable types to know the strengths and weaknesses of the written
program.

1. List variable type (list):


1.1. Advantage:

Flexibility: Elements can be added and removed flexibly from the list, making it easy to expand or shrink
the list depending on needs.

Easy to browse: List elements can be traversed using a loop, which is very convenient for processing a lot
of related data.

10
1.2. Defect:

Complicating the source code: In this case, you need to create two lists of info_chi and diem_st, increasing
the possibility of errors when entering and maintaining information.

Resource consuming: Because lists can contain many types of data, it is more resource consuming than
using fixed variables.

2. Fixed variable type (int, float):


2.1. Advantage:

Simplicity: Data stored in constant variable is simple and easy to understand.

Save resources: No need to use lists if there are only a few subjects.

2.2. Defect:

Limited flexibility: Variables need to be declared for each subject, which can become troublesome if the
number of subjects increases.

Difficult to expand: When you want to add new subjects, you have to change the source code structure

3. Note:

For not particularly large numbers of subjects, using fixed variables may be a more convenient
choice and reduce code complexity.

For large and fluctuating subjects, using lists can help to easily manage and expand information.

11
Choosing the variable type depends on your specific requirements and the level of flexibility needed
during development.

M2. Examine how the debugging process can be used to help develop more secure, robust
applications.
1. Check the input value:

Make sure that the values entered (credits and grades) are valid and match the program requirements.

Use print statements to print out the values of tin_chi and diem_st to see if they contain the correct
information.

The above is a user input error

2. Confirm the average score calculation logic:

Make sure that the logic in the point_avg_student function is correct. Maybe try printing out the values of
sum_point, count_tin_chi, and point to see if they contain the correct value.

Scoring function

3. Check archive files:

Confirm that you have write permission to the directory where you want to create the file. A relative or
full path can be used to ensure you are writing to the correct location.

Try printing out the file path to see if it's correct.

Try printing out the error message in the except block to see if there are detailed information about the
error.

12
Storage error

4. Exception handling:

Add correct exception handling to catch possible error types, such as ValueError or FileNotFoundError.

Try modifying some of the input values to see if the program handles errors correctly.

5. Test on execution environment:

Sometimes, the execution environment may have differences with the development environment. Try
running the program directly from the terminal or command prompt to test.

6. Use the built-in debugging tools:

Some IDEs (integrated development environments) have built-in debugging tools that help you monitor
variable values, step through lines of code, and view detailed error information. Use them if available.

Development environment debugging tools

7. Breaking down the problem:

If the problem is too complex, try breaking the program into smaller parts and testing each part one by
one.

8. Conclude:

If you want a program to develop robustly and safely, you need to pay attention to the debugging process
which can take time, and using testing and debugging techniques will help the program be more stable and
understand errors and bugs. how to fix them.

13
M3. Analyse the process of writing code, including the potential challenges faced.
1. Analyze the coding process.
1.1. Point_avg_student function:

Receiving two lists tin_chi_st and diem, note that you should check whether the two lists have the same
length before calculating.

Use the zip function to combine each pair of values from the two lists, then calculate the sum of the
products of each pair of values.

Calculate the total number of credits by taking the length of the tin_chi_st list.

Returns the cumulative average by dividing the sum of the products of credits and grades by the total
number of credits.

1.2. Show_point_of_student function:

Enter student name (name) and cumulative average score (points).

Displays student information and cumulative GPA.

Try opening and writing to the file 'data/point.txt'. If successful, the message "Write to file successfully".
If there is an error, report the error.

1.3. Enter information from users:

Use the input function to receive information from the user, including student name, number of credits and
score for each subject.

Store information in the variables full_name, tin_chi_1, tin_chi_2, tin_chi_3, diem_1, diem_2, diem_3.

14
2. Use list to store:

Use two lists tin_chi and diem_st to store the number of credits and corresponding points for each subject.

3. Calculate cumulative average score and display:

Call the point_avg_student function to calculate the cumulative average from the list of credits and grades.

Call the show_point_of_student function to display and save student information and cumulative GPA.

4. Potential challenges faced.


a) It is necessary to check the input value so that when entering a null value there will be no error
b) Test and report errors from the function. There should be additional checking and return of a
special value or error report if there is a problem with the input data.
c) The program targets an audience that needs high accuracy. If it wants to develop, it is necessary to
further improve the program to have more accurate calculations and serve more audiences.

IV. CONCLUSION
Through the above report, I hope to give a comprehensive view of the purpose for which this program was
created, I hope to provide an easier method of calculating average scores, helping students with Main math
scores as well as goals for the next semester or for the following years. In the problem of calculating
average scores for subjects, we have built an effective Python program to help students calculate
cumulative average scores based on scores and credits of each subject. The program not only uses
functions to reuse source code effectively, but also has the ability to handle errors and invalid input. In
short, solving this problem not only improves computing power, but also creates an efficient and
organized way to manage learning information, while providing flexible error handling to protect the
program from unwanted situations. Finally, I hope that this calculation program will become a useful tool
for lecturers, students and educators.

15
V. REFERENCE
1. VietTuts. (n.d.). List data type in Python - Learn Python programming. [online] Available at:
https://viettuts.vn/python-list [Accessed 28 Jan. 2024].

2. Learn With Experts. (2023). How To Write A Simple Python Program? Answering Questions Series
12. [online] Available at: https://hocvoichuyengia.com/lam-the-nao-de-viet-mot-chuong-trinh-python-
don-gian-giai-dap-thac-mac-seri-12/ [Accessed 28 Jan. 2024].

3. Learn IT online, learn programming from basic to advanced. (2022). The most basic and modern
debugging methods in Python. [online] Available at: https://funix.edu.vn/chia-se-kien-thuc/go-loi-
python/ [Accessed 28 Jan. 2024].

4. Teaching Each Other to Learn. (2021). Python code has error list index out of range. [online]
Available at: https://daynhauhoc.com/t/code-python-bi-loi-list-index-out-of-range/117322 [Accessed
28 Jan. 2024].

16

You might also like