{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tutorial A3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "__1__ Store the following lines in a suitable Python object while maintaining the indentation format:\n", "\n", " Twinkle, twinkle, little star,\n", " How I wonder what you are!\n", " Up above the world so high,\n", " Like a diamond in the sky.\n", " \n", " Twinkle, twinkle, little star,\n", " How I wonder what you are\n", " \n", "Display the object on the screen." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "__2__ Imagine you have a structure file from the RCS Protein Database (PDB) named `\"HSA-glucose_complexe.pdb\"`. Store the file name in a Python variable. Extract the base name of the file and the file extension and store both in separate variables. Now substitute the underscore (`_`) in the file name with a space (`\" \"`). Hint: the file extension corresponds to the four last characters of the the file name." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "__3__ \"A nut for a jar of tuna\" -- could this be a palindrome? How would you check with Python? Remove whitespace and convert all letters to lowercase while you do! What about the words \"lived\" and \"devils\"? Maybe they are if your join them." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "__Advanced 1__ Indentation is important in Python as we will see soon. It is recommended to use spaces instead of tabs. Imagine you have text stored as a string, where indentation is done using tabs (escape sequence `\\t`). Use the `expandtabs` string method (find out how it works) to convert tabs into 4 spaces." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Lorem ipsum dolor sit amet,\n", "\tconsectetur adipiscing elit,\n", "\tsed do eiusmod tempor incididunt ut labore\n", "et dolore magna aliqua.\n" ] } ], "source": [ "code = (\n", " \"Lorem ipsum dolor sit amet,\\n\"\n", " \"\\tconsectetur adipiscing elit,\\n\"\n", " \"\\tsed do eiusmod tempor incididunt ut labore\\n\"\n", " \"et dolore magna aliqua.\"\n", " )\n", "print(code)" ] } ], "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.6.10" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }