{ "nbformat_minor": 2, "nbformat": 4, "cells": [ { "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", "# `while` loop\n", "\n", "## Exercise 1\n", "\n", "Write a `while` loop which print numbers from 0 to 20 in increasing order without using the instruction `if` :" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# edit here" ], "outputs": [], "metadata": {} }, { "source": [ "Same question but in decreasing order:" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# edit here" ], "outputs": [], "metadata": {} }, { "source": [ "## Exercise 2\n", "\n", "What is the below program doing?:" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "a, b, c = 1, 1, 1\n", "while c < 11 :\n", " print(c, \": \", b)\n", " a, b, c = b, a+b, c+1" ], "outputs": [], "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# edit here" ], "outputs": [], "metadata": {} }, { "source": [ "## Exercise 3\n", "\n", "Using a `while` loop, write a function `orbit_product_of_digits(n)` which returns the list of successive iterations of the function which returns the product of digits, that is, `[n, product_of_digits(n), product_of_digits(product_of_digits(n)), ..., z]` until a computed number `z<10` is reached that can be written with only one digit:" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# edit here" ], "outputs": [], "metadata": {} }, { "source": [ "Can you find a number $n$ such that the length of the orbit is larger than 5?:" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# edit here" ], "outputs": [], "metadata": {} }, { "source": [ "... larger than 10?:" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# edit here" ], "outputs": [], "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 neglecting the terms of the sums that are less than $10^{-5}$ in absolute value:" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# edit here" ], "outputs": [], "metadata": {} } ], "metadata": { "kernelspec": { "display_name": "sagemath", "name": "sagemath" } } }