{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Popcorn Hack 1" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[5, 8, 11, 14, 17]\n" ] } ], "source": [ "x = [1,2,3,4,5]\n", "y = []\n", "def f(x):\n", " for i in x:\n", " y.append(3*(i+2)-4)\n", " return y\n", "print(f(x))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Popcorn Hack 2" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "103.0\n" ] } ], "source": [ "num1 = 20 ## num1 is 20\n", "num2 = num1 /2 ## num2 is num1 divided by 2\n", "## Num2 is 10\n", "num3 = num2 * 10 + 3 ## num3 is num2 times 10 plus 3\n", "## num3 will be 100 + 3\n", "print(num3) ## prints num3\n", "\n", "## code will print 103" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Popcorn Hack 3" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "35\n", "5\n", "300\n", "1.3333333333333333\n", "5\n" ] } ], "source": [ "num1 = 20\n", "num2 = 15\n", "\n", "print(num1 + num2)\n", "## Prints Addition\n", "\n", "print(num1 - num2)\n", "## Prints Subtraction\n", "\n", "print(num1 * num2)\n", "## Prints Multiplication\n", "\n", "print(num1 / num2)\n", "## Prints Division\n", "\n", "print(num1 % num2)\n", "## Prints MOD\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Popcorn Hack 4" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Torin Wolff\n", "5\n", "ri\n" ] } ], "source": [ "lastname = \"Wolff\"\n", "firstname = \"Torin\"\n", "print(firstname + \" \" + lastname)\n", "lenthlast=len(lastname)\n", "print (lenthlast)\n", "substringfirstname=firstname[2:4]\n", "print(substringfirstname)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Homework Hacks\n", "\n", "Using the three commands MOVE_FORWARD(), ROTATE_RIGHT(), ROTATE_LEFT(), and CAN_MOVE(). solving the problem. Command Sequence:CAN_MOVE(true), MOVE_FORWARD(), MOVE_FORWARD, MOVE_FORWARD(). ROTATE_LEFT(), MOVE_FORWARD(), MOVE_FORWARD(), ROTATE_RIGHT(), MOVE_FORWARD(), MOVE_FORWARD(), MOVE_FORWARD(). End of path." ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "55\n" ] } ], "source": [ "def fibonacci(number):\n", " if number == 0:\n", " return 0 ## if n is 0, return 0\n", " elif number == 1:\n", " return 1 ## if n is 1, return 1\n", " else:\n", " return fibonacci(number - 1) + fibonacci(number - 2) ## if n is not 0 or 1, return the sum of the previous two numbers\n", " \n", "print(fibonacci(10)) ## prints the 10th number in the fibonacci sequence. Can change to any number but 10 is a high number." ] } ], "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.11.5" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }