{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\def\\CC{\\bf C}\n",
    "\\def\\QQ{\\bf Q}\n",
    "\\def\\RR{\\bf R}\n",
    "\\def\\ZZ{\\bf Z}\n",
    "\\def\\NN{\\bf N}\n",
    "$$\n",
    "# Chapter 5: `while` loop\n",
    "\n",
    "## Exercise 1\n",
    "\n",
    "Write a `while` loop which print numbers from 0 to 20 in increasing\n",
    "order without using the instruction `if` :"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# edit here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Same question but in decreasing order:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# edit here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 2\n",
    "\n",
    "What is the below program doing?:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a, b, c = 1, 1, 1\n",
    "while c < 11 :\n",
    "    print(c, \": \", b)\n",
    "    a, b, c = b, a+b, c+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# edit here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 3\n",
    "\n",
    "Using a `while` loop, write a function `orbit_product_of_digits(n)`\n",
    "which returns the list of successive iterations of the function which\n",
    "returns the product of digits, that is,\n",
    "`[n, product_of_digits(n), product_of_digits(product_of_digits(n)), ..., z]`\n",
    "until a computed number `z<10` is reached that can be written with only\n",
    "one digit:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# edit here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Can you find a number $n$ such that the length of the orbit is larger\n",
    "than 5?:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# edit here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "... larger than 10?:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# edit here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercise 4\n",
    "\n",
    "The Taylor series of $\\sin(x)$ is\n",
    "\n",
    "$$\\sin x= \\lim_{n\\to\\infty}\\sum^{n}_{k=0} \\frac{(-1)^k}{(2k+1)!} x^{2k+1} = x -\n",
    "\\frac{x^3}{3!} + \\frac{x^5}{5!} - \\cdots$$\n",
    "\n",
    "Write a function `taylor_sin(x)` which evaluates the Taylor series\n",
    "neglecting the terms of the sums that are less than $10^{-5}$ in\n",
    "absolute value:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# edit here"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "sagemath",
   "name": "sagemath"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}