0% found this document useful (0 votes)
40 views19 pages

DSFSDFSDF

The document describes an assignment submission sheet for a computing fundamentals unit. It includes sections for student and assessor details, a grading grid, and space for feedback. It lists the contents to be included in the submission.

Uploaded by

qtrinh572
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views19 pages

DSFSDFSDF

The document describes an assignment submission sheet for a computing fundamentals unit. It includes sections for student and assessor details, a grading grid, and space for feedback. It lists the contents to be included in the submission.

Uploaded by

qtrinh572
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Computing Fundamental

Submission date Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Trinh Xuan Quyen Student ID BH02145

Class COM109.06 Assessor name DINH VAN DONG

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:

Grade: Assessor Signature: Date:


Lecturer Signature:
Contents
Intro ................................................................................................................. Error! Bookmark not
defined.
P1: Provide a definition of the data type that you use for the variables. ......................................................
5
1.1. Identify the variables used in the program. .................................................................................... 5
1.2. Specify the data type for each variable. .......................................................................................... 6
1.3. Briefly explain the reason for choosing the selected data type. ..................................................... 7
P2: Explain the error handling process. ..........................................................................................................
8
2.1. Describe the types of errors that the program might encounter. ......................................................
8
2.2. Outline the steps involved in handling errors using a try-except block. .............................................
8
P3: Determine the steps taken from writing code to execution. .................................................................
10
3.1. List the steps involved in writing and executing the program. .........................................................
10
3.2. Briefly explain the purpose of each step. ..........................................................................................
12
3.3. Identify the tools and resources used for writing and executing the program. ...............................
14
Conclusion ....................................................................................................... Error! Bookmark not
defined. References ....................................................................................................... Error! Bookmark
not defined.
introduction.
Python is a popular programming language. It was created by Guido van Rossum,
and released in 1991.

It is used for:

• web development (server-side),


• software development,
• mathematics,
• system scripting.
P1: Provide a definition of the data type that you
use for the variables.
1.1. Identify the variables used in the program.
• Variables are used to store information to be referenced and manipulated in a computer
program. They also provide a way of labeling data with a descriptive name, so our programs
can be understood more clearly by the reader and ourselves. It is helpful to think of variables
as containers that hold information. Their sole purpose is to label and store data in memory.
This data can then be used throughout your program.

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 must start with a letter or the underscore character

A variable name cannot start with a number

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)

A variable name cannot be any of the Python keywords.


https://www.w3schools.com/python/python_variables_names.asp

1.2. Specify the data type for each variable.


• In programming, data type is an important concept.
Variables can store data of different types, and different types can do different things.
Python has the following data types built-in by default, in these categories:
- Text Type: str

- Numeric Types: int, float, complex

- Sequence Types: list, tuple, range

- Mapping Type: dict

- Set Types: set, frozenset

- Boolean Type: bool

- Binary Types: bytes, bytearray, memoryview


None Type:
- NoneType
1.3. Briefly explain the reason for choosing the selected data type.
• To simplify the exercises, the operating language is short, without paragraphs between letters
and numbers. It also has the effect of clarifying the problem that needs to be solved.
P2: Explain the error handling process.
2.1. Describe the types of errors that the program might encounter.
Errors are the problems in a program due to which the program will stop the execution. On the other
hand, exceptions are raised when some internal events occur which changes the normal flow of the
program.

Two types of Error occurs in python :

1. Syntax errors
2. Logical errors (Exceptions)

Syntax errors

logical errors(Exception)

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


block.
Try Except in Python :
1. the try clause is executed i.e. the code between try.
2. If there is no exception, then only the try clause will run, except clause is finished.

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.

Use lists to store component scores and credits:

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.

Create a print_gpa() function:


Develop a function named print_gpa() to print the GPA score to the console or another output stream.
This function should take the calculated GPA score as input and print it in a user-friendly format.

Prompt the user for input:


Use input statements to prompt the user to enter the grades and corresponding credits for each course
component. This input will be stored in the lists created earlier.

Handle error cases and invalid input:


Implement error handling mechanisms to deal with invalid inputs or error cases gracefully. For example, if
the user enters a non-numeric value for the score or credits, the program should print an error message
and prompt the user to enter valid input.

Print the results to a text file:

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.

1. **Definition of `calculate_gpa` function:**


- **Purpose:** Defines a function named `calculate_gpa` that
computes the GPA based on the provided grades and their corresponding credits. This function
encapsulates the GPA calculation logic for reusability.

2. **Initializing `grade_points` dictionary:**

- **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.

3. **Initializing `total_credits` and `total_grade_points` variables:**

- **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.

4. **Iterating through `grades` dictionary:**


- **Purpose:** Loops through the `grades` dictionary, which contains letter grades as keys and their
corresponding credits as values. This loop calculates the total grade points and total credits based on the
provided grades and their weights.

5. **Calculating total grade points and total credits:**

- **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.

6. **Checking for total credits being zero:**

- **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.

7. **Calculating GPA and rounding to two decimal places:**

- **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.

8. **Example usage of `calculate_gpa` function:**

- **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.

Libraries and Packages:


Python has a vast ecosystem of libraries and packages that extend its functionality for various purposes,
such as data analysis, web development, machine learning, and more. Commonly used libraries include
NumPy, pandas, Matplotlib, TensorFlow, Django, Flask, and requests.

Introduction to PyCharm / Visual Studio

PyCharm:
1. Py
2. It
3. PyCh
4. It i

Visual Studio Code (VS Code):


1. VS Code i
2. It offers fea
3. VS C
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/

You might also like