# Notes for comp:
## Python:

### What are Variables?
* Boxes we can store data in.

### What is Casting?
* Used when we want to change a variable from one data type to another.

Example:

Age = 1 <br>
print(type(age)) → int

### What are F strings?
* Used as a handy way to join variables and other text into strings.

Example: <br>
Age =int( input(“What is your age?”))

<i>User enters 22 </i>

print(f”You are {age} years old)

<i>Displays: You are 22 years old</i>

### What are Booleans?
* A data type that can be either true or false

Example: <br>
apple = True

print (apple)

<i>Displays: True</i>

Banana = False

print (Banana)

<i>Displays: False</i>

### IF Statements
If : evaluates a condition that results in True or False

Else: statement is executed when the if condition (and any elif conditions) evaluate to False

### AND VS OR:
And will return true only if both conditions are true. Or will return true is at least one condition is true


### When to use while or for loops?
For loops iterate over a sequence and should be used when you have a defined number of iterations or a specific collection.

While loops used to repeatedly execute a block of code as long as a specified Boolean condition remains True.

### What are floats?
Non-integer numbers -> real numbers with decimal points

### What is Flask?
Flask is a interface framework that provides the tools necessary for building a website. It uses decorators* like @app.route('/') to provide specific URL routes for python functions.

### What are cookies?
Cookies are information stored on a users device through the web browser. They provide a more personalised experience as it acts as a digital memory between the server and browser.
Examples of what cookies store are shopping cart items. They also require a secret code so cookies can't be hacked, keeping data safe and secure.

### What are json files
Json files use to store information as well as transport data. Should be used when storing login in information and data that can be accessed by other users.

### Heuristics
They are features that allow users to achieve a goal more quickly and efficiently.
#### Learnability
How easy is it for users to use the WebApp without being told what to do.
#### Efficiency
Refers to how quickly a task can be accomplished.
#### Memorability
Once the user has used the WebApp, how memorable is it to accomplish the task.
#### Errors
How many errors do users make and is it a simple error to overcome or it is difficult to recover from.
#### Satisfaction
Based on the physical qualities o the WebApp, is it pleasant to use.<br>
What to think about?
* Visual cohesion across all page, utilising a consistent set of components -> if your input button are all dropdowns except for 1 radio button, while more common to use radio buttons for 2-3 options it is not consistent.
* Seamless transitions between pages: consistent spacing, alignment, layout to reduce cognitive load.

* Colour Palette: Ensuring the colouring aligns with the WebApp's purpose and audience.
* Red is an alarming colour, blue is neutral, and green means successful

### What is HTML?
Html which means HyperText Markup Language, and it provides a framework for websites. This includes the basis of layout, text, images, link e.t.c.

### Some HTML elements:
h1 - Heading

h2 - Smaller heading

p - Paragraph for grouping text together

br - adding in a break between lines

body - Contains the components to be displayed

a href - To add a link onto a specific text

img src - For adding in an image

alt - Shows up on screen instead when the image for some reason does not appear

b - bold

ul - unordered list

ol- ordered list

li- ordered list


head - contains the information that the user doesn't need to see, but everything else to make the WebApp what it is.

#### Tables in HTML

<table>
<tr>
<th> This is a (heading)</th>
<th> This is a (heading)</th>
</tr>
<tr> <td>This is row 1 col 1</td>
<td> This is row 1 col 2</td>
</tr>
</table>

### Why do we use PyHTML?
PyHTML is a library that allows use to combine html processes of creating the websites framework with the functionalities of python code.

### What is CSS?
A language used to style the HTML document and we use it because CSS has much more design capabilities and features than HTML.

#### Some CSS features:
<b> Background colour</b> : background-color: ;

<b> Text color</b>: color: ;

<b> Font </b>: font-family: ;

<b>Font size </b>: font-size: ;

### How to go about using the highly, complex, treacherous and very useful CSS Grid layout?
div<class = "container">
div <class = "item"> </div>
grid-template-columns: 1 fr 1 fr 1fr

### What are libraries?
Collections of pre-written code or functions that other developers can implement in their own coding without having to write it from scratch

### Python Packages Pro's and Con's
##### Pro's
* Don't need to reinvent the wheel as you can find code for almost anything.
* Less lines of code

##### Con's
* Some packages contain malicious code
* Code may be hard to understand

### API's
Code on a server that waits for requests and sends back responses

### Api's Pro's and Con's
##### Pro's
* Easy to use
* Faster development

##### Con's
* Your app will break if the APIs goes down
* Security ricks

### WebApp requirements
At the top : app = Flask(__name__)
At the bottom : if  __name__ == "__main__":
                app.run(port=5011)

### Accessing form data
data = request.form["data"]
Data must exist otherwise the app will crash
data = request.form.get("data", "")
If data does not exist it returns the value as ""

### Session
app.secret_key = 'Very Secret key is here'

### JsonHelpers
File name: jsonhelpers.py
* Written by Sim Mautner
* Current copy: 2026

import json
import os

* empty_data should be what data we want to put in there if the file doesn't exist
* either {} or [] as we are working with json files

def create_if_not_exist(filename, empty_data): <br>
    if not os.path.exists(filename): <br>
        write_json_file(filename, empty_data)

def write_json_file(filename, info_to_save): <br>
    my_file = open(filename, "w") <br>
    json.dump(info_to_save, my_file) <br>
    my_file.close()

def read_json_file(filename): <br>
    my_file = open(filename, "r") <br>
    information = json.load(my_file) <br>
    my_file.close() <br>
    return information
