GET 211 - Computing and Software Engineering-N1
GET 211 - Computing and Software Engineering-N1
Algorithm
An algorithm is a step-by-step procedure to resolve any problem.
An algorithm is an effective method expressed as a finite set of
well-defined instructions.
If source code is run instead, the operating system first loads the
interpreter into memory and starts a process. The interpreter
then loads the source code, translating and executing each
statement in real-time. This approach is slower than running an
executable and requires the interpreter to be installed on the
computer.
# Loops
print("Grades:")
for grade in grades: # Loop through the array
print(grade)
# Basic Operators
average_grade = sum(grades) / len(grades) # Arithmetic
operator
print(f"Average Grade: {average_grade}")
# Functions
def greet_user(username):
return f"Hello, {username}!"
print(greet_user(name))
# File I/O
with open("output.txt", "w") as file: # File writing
file.write(f"Name: {name}\n")
file.write(f"Age: {age}\n")
file.write(f"Average Grade: {average_grade}\n")
print("Data written to 'output.txt'.")
```
Explanation of Elements Used:
1. Programming Environment: The code can be written and
executed in a Python IDE or text editor.
2. Basic Syntax: Proper indentation and syntax rules are
followed (e.g., `if` conditions, loops).
3. Data Types: Strings (`"Alice"`), integers (`25`), and a list
(`[85, 90, 78]`).
4. Variables: `name`, `age`, and `grades` store data values.
5. Keywords: `if`, `else`, `for`, `def`, `with` are Python reserved
keywords.
6. Basic Operators: Arithmetic (`+`, `/`), comparison (`>=`).
7. Decision Making: An `if-else` block checks if the user is an
adult.
8. Loops: A `for` loop iterates through the grades.
9. Numbers: Used for age and grades.
10. Characters: Included in strings (e.g., names, messages).
11. Arrays: Represented by a Python list, `grades`.
12. Strings: Used for textual output and file writing.
13. Functions: `greet_user` demonstrates a reusable function.
14. File I/O: Writes the user’s data to a file named `output.txt`.