DSFSDFSDF
DSFSDFSDF
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 Quyen
Grading grid
P1 P2 P3 M1 M2 M3 D1 D2 D3
Summative Feedback: Resubmission Feedback:
It is used for:
Variable Names
A variable can have a short name (like x and y) or a more descriptive name (age, carname,
total_volume). Rules for Python variables:
A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
Variable names are case-sensitive (age, Age and AGE are three different variables)
1. Syntax errors
2. Logical errors (Exceptions)
Syntax errors
logical errors(Exception)
3. If any exception occurs, the try clause will be skipped and except clause will run.
4. If any exception occurs, but the except clause within the code
doesn’t handle it, it is passed on to the outer try statements. If the exception is left unhandled,
then the execution stops.
5. A try statement can have more than one except clause
P3: Determine the steps taken from writing code to
execution.
3.1. List the steps involved in writing and executing the program.
Create a calculate_gpa() function:
Write a function named calculate_gpa() that takes a list of component scores and credits as input and
calculates the GPA score based on a predefined formula. This function should return the GPA score.
Utilize lists to store the component scores and corresponding credits. Each item in the list represents a
pair of (score, credit) for a specific course component.
After calculating the GPA score, write the results to a text file for record-keeping or future reference. You
can use file handling operations in Python to create, open, write to, and close the text file.
Tuple in Python and its Usage:
Definition: A tuple in Python is an immutable sequence of elements, enclosed within parentheses (), and
separated by commas. Unlike lists, tuples cannot be modified after creation.
Each step mentioned above should be implemented as a function or a set of functions.Proper error
handling should be incorporated to handle any potential errors or invalid inputs.Comments should be
added to the source code to explain the purpose and functionality of each function or block of
code.Modularization and code organization should be followed to maintain clarity and readability of the
code.Output to a text file can be achieved using file handling operations such as open(), write(), and
close() functions.
3.2. Briefly explain the purpose of each step.
- **Purpose:** Creates a dictionary named `grade_points` that maps letter grades to their
corresponding grade points. This dictionary serves as a lookup table for converting letter grades to grade
points.
- **Purpose:** Initializes two variables, `total_credits` and `total_grade_points`, to keep track of the
cumulative sum of credits and grade points, respectively. These variables will be used to compute the
GPA.
- **Purpose:** Computes the total grade points and total credits by iterating through the `grades`
dictionary. It multiplies the grade point of each grade by its corresponding credits and accumulates the
results.
- **Purpose:** Checks if the total credits are zero to avoid division by zero error when calculating the
GPA. If `total_credits` is zero, it returns a GPA of 0.0 to handle this special case.
- **Purpose:** Computes the GPA by dividing the total grade points by the total credits. It rounds the
GPA to two decimal places using the `round` function to maintain precision.
- **Purpose:** Demonstrates how to use the `calculate_gpa` function by providing an example grades
dictionary. It calculates the GPA based on the provided grades and prints the result.
Each step in the code contributes to the overall process of calculating the GPA, from initializing variables
and iterating through the grades to computing the GPA value and providing an example usage scenario.
3.3. Identify the tools and resources used for writing and executing
the program.
PyCharm: PyCharm is a popular Python IDE developed by JetBrains. It offers features such as code
completion, syntax highlighting, debugging tools, version control integration, and support for web
development frameworks like Django and Flask.
Visual Studio Code (VS Code): VS Code is a lightweight but powerful code editor developed by Microsoft. It
supports various programming languages, including Python, and provides features like IntelliSense,
debugging, version control, and extensions for customization.
Python Interpreter:
The Python interpreter is the core component that executes Python code. It converts Python code into
machine-readable instructions and executes them. The interpreter comes bundled with the Python
installation.
PyCharm:
1. Py
2. It
3. PyCh
4. It i
Conclusion.
THANK FOR READING.
References.
Geeksforgeeks: https://www.geeksforgeeks.org/errors-and-exceptions-in-python/?ref=lbp
w3schools :https://www.w3schools.com/python/python_ref_keywords.asp
https://launchschool.com/