{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Exercises: python basics" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercise 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", "## Exercise 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", "## Exercise 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", "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\"\t: 716,\n", " \"Neurosciences\"\t: 431,\n", " \"Other biological sciences\"\t: 3675,\n", " \"Computer sciences\"\t: 856,\n", " \"Earth, atmospheric, and ocean sciences\" : 706,\n", " \"Mathematics\" : 1083,\n", " \"Chemistry\"\t: 2132,\n", " \"Physics and astronomy\"\t: 715,\n", " \"Astrology\" : 2012, \n", " \"Psychology\" : 3668,\n", " \"Social sciences\" : 4063}\n", "\n", "engineering_doc = {\"Aerospace/aeronautical engineering\"\t: 206,\n", " \"Chemical engineering\"\t: 576,\n", " \"Civil engineering\"\t: 506,\n", " \"Electrical engineering\" : 1236,\n", " \"Industrial/manufacturing engineering\" : 211,\n", " \"Materials science engineering\"\t: 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", "## Exercise 1.5\n", "set a variable called `isDivisible` to `True` if 7453102041884640481897 is evenly divisible by 135138672131" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "## Exercise 1.6\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", "## Exercise 1.7\n", "1. Build a list containing the name of all swiss cantons.\n", "2. sort it\n", "3. reverse it\n" ] } ], "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.5" } }, "nbformat": 4, "nbformat_minor": 4 }