Professional Documents
Culture Documents
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.
Grading grid
P1 P2 P3 M1 M2 M3 D1 D2 D3
Summative Feedback: Resubmission Feedback:
P1: Provide a definition of the data type that you use for the
variables.
The variable is part of the program used to store data. Once the variable has been stored, that is, a
space has been allocated in that memory. Based on the type of data of a variable, explaining the creation
of memory and deciding what can be stored in that reserved memory area. Therefore, by assigning
different data to variables, you can store integers, texts, decimals for variables.
The variable is used to store and refer to data values. The variable can be considered as "boxes"
containing information, and they can change the value during the implementation of the program.
Principle of naming variables:
• The name of the variable must be started with a word or an underscore character (lower
bricks: _).
• The name of the variable cannot start with a number. In addition to the output character, in
the variable name can use the number, letters and lower bricks as usual.
• The variable in Python must have a proper name, not duplicating with the names of the
variables existing on your working file.
• The variable name of the flora and normal letters.
Referencing websites:
https://stringee.com/vi/blog/post/kieu-du-lieu-trong-python
1.2. Specify the data type for each variable.
Integers include positive integers (1, 2, 3, ..), negative integers (-1, -2, -3) and 0. In Python, the
integer data type is no different special.
Example of integers: Assign a value to a variable a of 4 and output the data type of a.
Regarding the real number data type, this is a set of integers and decimal numbers 1, 1.4, -123,
69.96,...
Example of real number: Assign the value of variable f to 1.23 and output the data type of f.
Example:
Bool (Boolean) type in Python is the type of data in which only two values True and False. True
and False are two keywords in Python.
The collection data type is represented by Dict data structure, abbreviated for the word
"Dictionary". A set of data is a data structure that you can store the non-ordered values. Each key must be
unique in the set and is used to access the corresponding value.
Referencing websites:
https://howkteam.vn/course/lap-trinh-python-co-ban/kieu-du-lieu-so-trong-python-1540
https://tuhocict.com/kieu-du-lieu-bool-trong-python/
1.3. Briefly explain the reason for choosing the selected data type.
There are many reasons to choose an integer variable, including:
o Accuracy: variable integer type of integer values accurate, not rounded or lost accuracy due
to rounding errors. This is very important for applications that need high accuracy, such as
financial or scientific applications.
o Performance: The integer variable is usually processed faster than other data types, such as
Float variable. This is due to simpler operations and requires less memory resources.
o Memory size: integer variable is usually smaller than other data types, such as Float
variable (float). This can save memory, especially when storing large amounts of data.
o Compatibility: The integer variable is supported by most programming languages and can
often be used with other data types easily.
For example: To store the number of students in a classroom, you should use an integer variable
because the number of students is an accurate integer.
o Range: Float variables can store a wider range of values than integer variables. This is
important for applications that need to store very large or very small values.
o Precision: Float variables can store numeric values with high precision, although not as
precise as integer variables. This is important for applications that need to perform complex
calculations or process scientific data.
o Flexibility: Float variables can be used to store both integer and float values. This can help
simplify the code and reduce the number of variables needed.
For example: To store the average of test scores in a class, you should use a float variable because
the average can be a decimal number.
o Storing text: String variables are used to store text, such as names, addresses, or messages.
o Text processing: String variables can be used to perform mathematical operations with text,
such as string concatenation and search and replace.
o Communication: String variables are used to communicate data with users or other
programs.
For example: To store a student's name, you should use a string variable.
Referencing websites:
https://gemini.google.com/app/42f48b73915abab2
P2: Explain the error handling process.
2.1. Describe the types of errors that the program might encounter.
There are two main types of errors that need to be handled in Python programs:
Syntax Error:
• Occurs when the grammar rules of the Python language are violated.
• For example: misspelled keywords, missing brackets, wrong indentation.
• Python immediately reported an error, unable to continue executing the program.
Exception:
• Error handling:
In the except block, write code to handle the caught error.
3.1. List the steps involved in writing and executing the program.
The process of step by step handling the problem and explaining each step of the program:
•
o Example of a code snippet that displays data on the screen:
Program implementation:
o Defining the calculate_gpa function: First, the program defines a function called
calculate_gpa, which is used to calculate GPA based on the scores and credits of the
entered subjects.
o Data processing: The program goes through each item in the grades dictionary, checks
whether the grades are valid or not, calculates the total number of credits and total GPA
based on the grade and number of credits for each subject.
o Calculate and export results: Then, the program calculates the final GPA by dividing
the total GPA by the total number of credits and outputs the results to the console
screen.
o Writing results to a text file: GPA results are written to the text file "gpa_results.txt" by
opening the file with write mode and writing the results as the string "GPA:
{gpa_score}".
Tools and resources used to write and execute programs:
• Python Interpreter:
o You need to have Python installed on your computer. Make sure you are using Python
version 3.x as it supports features like f-string which you used in the program to write the
file.
• Integrated Development Environment (IDE) or Text Editor:
o IDEs like PyCharm, Visual Studio Code, or Jupyter Notebook: These tools support Python
development by providing features like debugging, code completion, and environment
management.
• Command Line Interface (CLI):
o Terminal (macOS or Linux) or Command Prompt (Windows): To run Python commands
from the command line and execute scripts.
• Basic knowledge of Python:
o Understanding of control structures (loops, conditional statements), how to work with
dictionaries, and how to handle files.
• File system access rights:
o Make sure you have permission to create and write to files in the directory you are working
in.
• Visual Studio Code is a light but powerful source editing process, running on your desktop
and available for Windows, MacOS and Linux. It comes with integrated support for
JavaScript, TypeScript and Node.js, and has a rich expansion ecosystem for other
languages and running time (such as C ++, C#, Java, Python , PHP, GO, .NET).
…………………………End…………………………
Thank you to those who read and rated this essay. Thanks!!
References:
Referencing Wedsite: https://chat.openai.com/