{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Try it yourself!" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "cLfvUyyxGyXH" }, "outputs": [], "source": [ "class Alien:\n", " def __init__(self, name):\n", " self.name = name\n", " self.energy = 10\n", "\n", " \n", " def move(self, distance=1):\n", " if self.energy < steps:\n", " print(\"I don't have the energy to move that far\")\n", " else:\n", " self.energy -= steps\n", " \n", " def sleep(self):\n", " self.energy = 10\n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "fwb0mHZPHOdW" }, "outputs": [], "source": [ "class MyAlien(Alien): # give your alien a unique name\n", " def __init__(self, name):\n", " super().__init__(name)\n", " # define two more attributes your alien has\n", " \n", " # think of a unique way to display your alien's attributes\n", " def __str__(self):\n", " s = 'How should you display your alien?'\n", " return s\n", "\n", "\n", " # think of two new actions your alien can do\n", " def action1(self):\n", " pass\n", " \n", " def action2(self):\n", " pass" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "w08zITUNIDJ-" }, "outputs": [], "source": [ "# Use this space to initialize and display a new instance of your alien" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "ipjlZtVwIJrq" }, "outputs": [], "source": [ "# have your alien move some distance\n", "\n", "# display their new energy level" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "dLt6t_n4INJ0" }, "outputs": [], "source": [ "# have your alien sleep\n", "\n", "# display their new energy level" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "OZt8KJvJIPlU" }, "outputs": [], "source": [ "# use this space to have your alien perform the first new action\n", "# did any attributes change?" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "4PuSCcWgIWo1" }, "outputs": [], "source": [ "# use this space to have your alien perform the second new action\n", "# did any attributes change?" ] } ], "metadata": { "colab": { "name": "alien.ipynb", "provenance": [] }, "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.6" } }, "nbformat": 4, "nbformat_minor": 1 }