{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "767ad1b8",
   "metadata": {},
   "source": [
    "# Python Variables and Lists"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5d1bc8d2",
   "metadata": {},
   "source": [
    "## Python variables\n",
    "**Variables** in python are like a labeled box that stores a value so you can use it later in your program.\n",
    "They are created using ``var_name = 1`` for example.\n",
    "\n",
    "The value you give to a variable can have different **types** :\n",
    "* _int_ : Integers are numbers where we ignore what comes after the decimal point.\n",
    "* _float_ : Floating point values are numbers that can have any precision after the decimal point. When you do not need to know what comes after the decimal point, prefer using integers.\n",
    "* _bool_ : Are True/False values. They can only take the values ``True`` and ``False``.\n",
    "* _string_ : Strings are the python words for normal text. Define them using \" or '.\n",
    "* _List_ : List will be explored later on. They are a collection of different values.\n",
    "* And many more !\n",
    "\n",
    "\n",
    "Create two variables a and b and assign some values, then use the inbuilt function ``print()`` to display them, and do some simple operations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4ccb3cf0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "61a11e6c",
   "metadata": {},
   "source": [
    "## Python Lists\n",
    "\n",
    "Python lists are a collection of values that can have different types.\n",
    "They are created using brackets, and specifying a list of elements : ``my_list = [1,5,6]``.\n",
    "Accessing the list is done by indicating the indices of the value you want to access using brackets.\\\n",
    "Python starts counting from 0 : ``element_3 = my_list[2]``\n",
    "\n",
    "Create a list with 7 values, they can be integers, strings, floats ...\n",
    "Try to access the values 0, 3, 7, -1.\n",
    "\n",
    "You can run some basic functions to get information on the list, such as ``len(my_list)``. Try printing the size of your list."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "158ba097",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "9b421d65",
   "metadata": {},
   "source": [
    "## Python Loops\n",
    "Loops are functions that allow to repeat a certain set of instructions.\n",
    "\n",
    "**While** loops repeat as long as a certain condition is verified, if this condition cannot be satisfied, this may lead to an infinite loop ! **Conditions** in python are mathematical equations that can be answered by a simple ``True`` or ``False``.\n",
    "\n",
    "**For** loops create a variable that will go through a set of values, and the loop will be exited afterwards.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e7ef4653",
   "metadata": {},
   "source": [
    "Create a **While** loop that prints all the values from your list, one after the other.\n",
    "This could be done with 7 lines of code, but imagine this now with a list of 1000 elements !"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8091ffe9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "7e304298",
   "metadata": {},
   "source": [
    "Now create **While** loop that returns the total sum of the list.\n",
    "(Since we added some \"none number\" values, you may need to create a new list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6dd93879",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "afcdc0a2",
   "metadata": {},
   "source": [
    "As mentioned, python provides some basic functions to help you so you don't have to write basic codes like the sum."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c02d18f1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "d0326db0",
   "metadata": {},
   "source": [
    "Sometimes we need to add lists together, as you would with a matrix.\n",
    "\n",
    "Create two lists and add them together. (Make sure they are made of only numbers !). Does this do what you expect it to do ?"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
