{ "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", "# `if` statements\n", "\n", "## Exercise 1" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "if a != 2: \n", " print('lost')\n", "elif a == 3:\n", " print('an instant, please')\n", "else: \n", " print('you win')" ], "outputs": [], "metadata": {} }, { "source": [ "What is the above program doing\n", "\n", "> - when variable `a` is 1?\n", "> - when variable `a` is 2?\n", "> - when variable `a` is 3?\n", "> - when variable `a` is 15?" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# edit here" ], "outputs": [], "metadata": {} }, { "source": [ "## Exercise 2\n", "\n", "Write a for loop which counts the number of consonnants in a string:" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "s = 'how many consonants are present in this sentence?'" ], "outputs": [], "metadata": {} }, { "source": [ "## Exercise 3\n", "\n", "Write a for loop which finds the largest element in a given list. For example, if the list is `[32, 5, 12, 8, 3, 75, 2, 15]` it should print : `the largest element of the list is 75` :" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# edit here" ], "outputs": [], "metadata": {} }, { "source": [ "## Exercise 4\n", "\n", "Write a for loop which analyze one by one every element of a list of numbers and generates two new lists: one list contains only the even numbers, the other containing the odd numbers of the given list:" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# edit here" ], "outputs": [], "metadata": {} }, { "source": [ "## Exercise 5\n", "\n", "Write a for loop which analyze one by one every element of a list of strings (for example : `['Jean', 'Maximilien', 'Brigitte', 'Sonia', 'Jean-Pierre', 'Sandra']`) and generates two new lists: one list contains every string contains less than 6 characters, the other containing string with 6 or more characters:" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": null, "cell_type": "code", "source": [ "# edit here" ], "outputs": [], "metadata": {} } ], "metadata": { "kernelspec": { "display_name": "sagemath", "name": "sagemath" } } }