{ "metadata": { "kernelspec": { "name": "python", "display_name": "Python (Pyodide)", "language": "python" }, "language_info": { "codemirror_mode": { "name": "python", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8" } }, "nbformat_minor": 5, "nbformat": 4, "cells": [ { "id": "80c19b23-b438-47c9-a982-1b0ab88dae87", "cell_type": "markdown", "source": "
Your techer will demonstrate several key skills, you may code along with your teacher if you wish to do so
\n\nUse what you have just learned to complete the activities below
\nHere are some code snippets to help you with your code
\n\n\n\nprint(desserts[3])\n\n
Outputs from the first index number, up-to (but not including) the last index number
\n\nprint(desserts[6:12])\n\n
Outputs a list item within a string
\n\nprint(f\"You have ordered {desserts[7]}\")\n \nTo run the cell, press CTRL and Enter ⌨️
\n\n\nYour techer will demonstrate several key skills, you may code along with your teacher if you wish to do so
\n\nUse what you have just learned to complete the activities below
\nHere are some code snippets to help you with your code
\n\nCreating a list
\n\nlistylistlistlist = [\"item1\",\"item2\",\"item3\",\"item4\"]\n\n
Iterating through a list
\n\nfor item in listylistlistlist:\n print(item)\n\n
In this activity, you will ammend the code for activity B so that it outputs in two separate sections like so
\n\nWith a for loop, you can also loop through a specific range of items
\nAs you have seen earlier, a range is up-to (but not including) the last item
\nEven if the last item of a list is 5, you can put 6 in order to display item 5 (even though item 6 technically doesn't exist!)
\nHere is a code snippet to help you with your code, this will print items 0, 1, 2 and 3 of the list
\n\n\nfor each in range(0,4):\n print(listitem[each])\n\n
In this activity, you will ammend the code for activity B so that it outputs \"short name\" next to planets who's names are 5 characters or less and long name next to planets who's names are longer
\n\nUsing selection IF / ELSE and the len() function, you can check to see if a string is a certain length
\nThe code below checks to see if a string is smaller than 8 characters
\nObviously, as this is an extension task, you must adapt it to check a list item during each iteration!
\n\n\nmystring = \"dodecahedron\"\n \nif len(mystring) < 8:\n print(f\"mystring has less than 8 characters!\")\nelse:\n print(f\"mystring has 8 or more characters!\")\n\n