{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Exercises: python basics" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercice 1.1 \n", "What does `myString[0:10:2]` do? \n", "What could the `2` mean in that context?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "## Exercice 1.2 \n", "I am trying to make a division. Could you make my code work?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a=12\n", "b='36'\n", "division = b/a\n", "print(division)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "## Exercice 1.3 \n", "1. Put your favorite quote in a string variable.\n", "2. Find a way to replace all spaces by '@' in the quote." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "## Exercise 1.4\n", "Use the `find()` method to determine the position(s) of the motif \"CTCGA\":\n", " \n", "GTGCCCCTCGAGAGGAGGGCGCGCGCCGCGCGCTCGACGCGATCGGCGCTCAGCGAGCGAGCTCCTCGAAGCGATCCGCGCGCGCT\n", "\n", "What is a limitation here?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "\n", "# Additonal Exercises\n", "\n", "## Additional Exercise 1.1\n", "Consider the two dictionnaries below, describing the number of PhD degrees delivered in 1999 in the US (adapted from [nsf data](http://www.nsf.gov/statistics/infbrief/nsf11305/)):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "science_doc = {\"Agricultural sciences\": 1065,\n", " \"Biochemistry\": 759,\n", " \"Molecular biology\": 716,\n", " \"Neurosciences\": 431,\n", " \"Other biological sciences\": 3675,\n", " \"Computer sciences\": 856,\n", " \"Earth, atmospheric, and ocean sciences\": 706,\n", " \"Mathematics\": 1083,\n", " \"Chemistry\": 2132,\n", " \"Physics and astronomy\": 715,\n", " \"Astrology\": 2012, \n", " \"Psychology\": 3668,\n", " \"Social sciences\": 4063}\n", "\n", "engineering_doc = {\"Aerospace/aeronautical engineering\": 206,\n", " \"Chemical engineering\": 576,\n", " \"Civil engineering\": 506,\n", " \"Electrical engineering\": 1236,\n", " \"Industrial/manufacturing engineering\": 211,\n", " \"Materials science engineering\": 393,\n", " \"Mechanical engineering\": 786,\n", " \"Other engineering\": 1416 }\n", "\n", "humanities_doc = {\"Foreign languages and literature\": 626,\n", " \"History\": 960,\n", " \"Letters\": 1516,\n", " \"Other humanities\": 1934}\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. merge these three dictionnaries in a `all_doc` dictionnary\n", "2. what is the length of the `all_doc` dictionnary\n", "3. add the \"Health\" doctorates of the `all_doc` dictionnary, with 1407 degrees awarded.\n", "4. multiply by 2 the number of Physics and astronomy degrees in `all_doc`.\n", "5. remove the Astology key from `all_doc`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "## Additional Exercise 1.2\n", "set a variable called `isDivisible` to `True` if 7453102041884640481897 is evenly divisible by 135138672131" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "## Additional Exercise 1.3\n", "\n", "Here is a list containing the name of all swiss cantons.\n", "\n", "1. sort it alphabetically\n", "2. reverse it\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cantonList = [\n", " 'Zürich',\n", " 'Bern',\n", " 'Luzern',\n", " 'Uri',\n", " 'Schwyz',\n", " 'Obwalden',\n", " 'Nidwalden',\n", " 'Glarus',\n", " 'Zug',\n", " 'Fribourg',\n", " 'Solothurn',\n", " 'Basel-Stadt',\n", " 'Basel-Landschaft',\n", " 'Schaffhausen',\n", " 'Appenzell Ausserrhoden',\n", " 'Appenzell Innerrhoden',\n", " 'St. Gallen',\n", " 'Graubünden',\n", " 'Aargau',\n", " 'Thurgau',\n", " 'Ticino',\n", " 'Vaud',\n", " 'Valais',\n", " 'Neuchâtel',\n", " 'Geneva',\n", " 'Jura']" ] } ], "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.8.6" } }, "nbformat": 4, "nbformat_minor": 4 }