{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercises" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Try these exercises to test your knowledge of strings!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q1. Create a string named __abc__, which contains the characters \"My cat's name is Fluffy\"." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q2. Ask the computer to print __abc__." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q3. Convert __abc__ to capitals, and print the result." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q4. Print the length of __abc__." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q5. Get the character in position 5 in the string __abc__." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q6. Find the first character in the string __abc__. (Remember: the first character is not the same as the character in position 1!)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q7. Ask the computer how many times the character \"f\" appears in __abc__." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q8. Ask the computer how many times the character \"F\" appears in __abc__." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q9. Print the number of times the string \"cat's\" appears in __abc__." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q10. Create a new string called __name__, by replacing the string \"Fluffy\" with \"Ginger\" in __abc__.
    Print __name__." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's try something a bit more exciting! This is an excerpt from *Harry Potter and the Prisoner of Azkaban*:

\n", "*Harry sat down between Dudley and Uncle Vernon, a large, beefy man with very little neck\n", "and a lot of moustache. Far from wishing Harry a happy birthday, none of the Dursleys\n", "made any sign that they had noticed Harry enter the room, but Harry was far too used to\n", "this to care. He helped himself to a piece of toast and then looked up at the reporter on the\n", "television, who was halfway through a report on an escaped convict.*

\n", "Q11. Create a string with this text in it, and call it __harry__.   (Hint. It may help to copy and paste!)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q12. Print __harry__. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q13. Find the length of the string __harry__. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q14. Print the character in position 100 in __harry__." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q15. Convert __harry__ to lowercase, and call this new string __harry_lower__.
   Print __harry_lower__." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q16. Print how many times each of the vowels appear in __harry_lower__." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }