{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2c7d713",
   "metadata": {},
   "outputs": [],
   "source": [
    "def fact(n):\n",
    "    \"\"\" Υπολογισμός παραγοντικού \"\"\"\n",
    "    p = 1\n",
    "    for i in range(1, n+1):\n",
    "        p *= i\n",
    "\n",
    "    return p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "062ffb00",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(fact(3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5bd29878",
   "metadata": {},
   "outputs": [],
   "source": [
    "result = fact(5) # αποθήκευση αποτελέσματος συνάρτησης σε μεταβλητ΄ή\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b7638d72",
   "metadata": {},
   "source": [
    "Συνάρτηση χωρίς όρισμα"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3fc4f00f",
   "metadata": {},
   "outputs": [],
   "source": [
    "def greet():\n",
    "    print('Hello, world!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b0878dcc",
   "metadata": {},
   "outputs": [],
   "source": [
    "greet()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4e9a5ef4",
   "metadata": {},
   "source": [
    "Συναρτήσεις με προκαθορισμένες τιμές"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8a2513f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "def add(a, b=10):\n",
    "    return a + b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "02ef4de4",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(add(2))\n",
    "print(add(2,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7baa2e21",
   "metadata": {},
   "outputs": [],
   "source": [
    "def add3(a, b=10, c=1):\n",
    "    return a + b + c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c894c752",
   "metadata": {},
   "outputs": [],
   "source": [
    "add3(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6df60d79",
   "metadata": {},
   "outputs": [],
   "source": [
    "add3(1, c=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3ea95309",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Quiz 1\n",
    "def molar_mass_water():\n",
    "    M = 2*1.008 + 16.00\n",
    "    print(M)\n",
    "\n",
    "x = molar_mass_water()\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "31de1148",
   "metadata": {},
   "source": [
    "Προσοχή στη σειρά των ορισμάτων"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4fe13927",
   "metadata": {},
   "outputs": [],
   "source": [
    "def sum_pow(x,y):\n",
    "    s = x + y\n",
    "    p = x**y\n",
    "    return s, p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "73bd64ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "sum_pow(3,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "09a87d12",
   "metadata": {},
   "outputs": [],
   "source": [
    "ans_1, ans_2 = sum_pow(3,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2b67fec0",
   "metadata": {},
   "outputs": [],
   "source": [
    "ans_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5179eec1",
   "metadata": {},
   "outputs": [],
   "source": [
    "type(sum_pow(3,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4ddf47db",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Προσοχή στη σειρά των ορισμάτων!\n",
    "sum_pow(3,2) == sum_pow(2,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b629019f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Quiz 2\n",
    "def ideal_gas_P(n, T, V=1.0, R=0.08206):\n",
    "    return n*R*T/V\n",
    "\n",
    "P = ideal_gas_P(2, 300, 4)\n",
    "\n",
    "print(P)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f44e348",
   "metadata": {},
   "source": [
    "lambda functions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a1894d08",
   "metadata": {},
   "outputs": [],
   "source": [
    "equation = lambda a, b, c, x: a*(x**2) + b*x + c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2f0ae31",
   "metadata": {},
   "outputs": [],
   "source": [
    "equation(4, 3, 3, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2154ab64",
   "metadata": {},
   "outputs": [],
   "source": [
    "equation(4,3,3,0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3901b538",
   "metadata": {},
   "source": [
    "exercise"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a1c9f625",
   "metadata": {},
   "outputs": [],
   "source": [
    "def celsius_to_kelvin(celsius):\n",
    "    kelvin = celsius + 273.15\n",
    "    return kelvin"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e991cb97",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(celsius_to_kelvin(25))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "63f2a5fd",
   "metadata": {},
   "source": [
    "global and local variables"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae8b52ff",
   "metadata": {},
   "outputs": [],
   "source": [
    "PI = 3.14\n",
    "\n",
    "def cyl_volume(r, L):\n",
    "    vol = PI*r**2*L\n",
    "    return vol"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "98f53376",
   "metadata": {},
   "outputs": [],
   "source": [
    "cyl_volume(2, 8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9a1399f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(vol)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "057ac39a",
   "metadata": {},
   "outputs": [],
   "source": [
    "z = 10\n",
    "\n",
    "def func_1(x, y):\n",
    "    z = x + y\n",
    "    return z"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "80672a42",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(func_1(2,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a2aa804e",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0532b82d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Quiz 3\n",
    "T = 298\n",
    "\n",
    "def heat(T):\n",
    "    T = T + 50\n",
    "    return T\n",
    "\n",
    "T_new = heat(T)\n",
    "print(T, T_new)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b32a909e",
   "metadata": {},
   "source": [
    "Κλήση εξωτερικής συνάρτησης"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20bcf6f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "from bubble_sort import bubble_sort"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1a1a39d4",
   "metadata": {},
   "outputs": [],
   "source": [
    "num_lst = []\n",
    "for num in range(10):\n",
    "    x = float(input('Give a number:'))\n",
    "    num_lst.append(x)\n",
    "    \n",
    "print(num_lst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4bd25047",
   "metadata": {},
   "outputs": [],
   "source": [
    "sorted_list = bubble_sort(num_lst.copy()) # προσοχή η λίστα είναι μεταλλάξιμη\n",
    "print(sorted_list)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
