{ "cells": [ { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 EVEN\n", "1 ODD\n", "2 EVEN\n", "3 ODD\n" ] } ], "source": [ "#4: Write a function called showNumbers that takes a parameter called limit. \n", "#It should print all the numbers between 0 and limit with a label to identify the even and odd numbers. \n", "#For example, if the limit is 3, it should print:\n", "#0 EVEN\n", "#1 ODD\n", "#2 EVEN\n", "#3 ODD\n", "\n", "def showNumbers(limit):\n", " for x in range(limit+1):\n", " if x%2 == 0:\n", " print(x,\"EVEN\")\n", " else:\n", " print(x,\"ODD\")\n", "\n", "showNumbers(3)\n", "#if C1:\n", "# ???\n", "#elif C2:\n", "# ???\n", "#elif C3:\n", "# ???\n", "#\n", "#else:\n", "# ???" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x = 12\n", "x%2 == 0" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import string\n", "\n", "def encrypt(s):\n", " # this function returns the encrypted form of s\n", " # s = \"14:00/the ships are in position\"\n", " key = int(s[0:2])\n", " k = s.index('/')\n", " plain = s[k+1:]\n", " init_string = s[0:k+1]\n", " #Strategy 1:\n", " for c in plain:\n", " ???\n", " \n", " #Strategy 2:\n", " for word in plain.split():\n", " ???\n", " \n", " \n", " return answer\n", " # answer = \"14:00/7,21,18_6,21,22,3,6_14,5,18_22,1_3,2,6,22,7,22,2,1\"\n", "\n", "\n", "###SLICE-DICE-STITCH STRINGS!!!!\n", " \n", " \n", " \n", " \n", "def decrypt(s):\n", " # this function returns the decrypted form of s\n", " ???\n", "\n", "def main():\n", " #s = \"14:00/the ships are in position\"\n", " #s = \"21:30/17,25_21,12,25_12,25,21,24,19_14,9_21,14,14,21,23,5\"\n", " while True:\n", " s = input(\"\\nEnter e plain-text or d coded-text or q: \")\n", " if s[0] == \"e\":\n", " print(\"Encrypted text is: \"+encrypt(s[2:]))\n", " elif s[0] == \"d\":\n", " print(\"Decrypted text is: \"+decrypt(s[2:])) \n", " elif s[0] == \"q\":\n", " break\n", " else:\n", " print(\"Invalid choice\")\n", "\n", "main()" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'344'" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s = \"14:00/the ships are in position\"\n", "int(s[0:2])\n", "str(344)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "namaste\n", "howdy\n", "howdy/namaste\n" ] } ], "source": [ "s = \"namaste/howdy\"\n", "k = s.index(\"/\")\n", "fw = s[0:k]\n", "sw = s[k+1:]\n", "nw = s[k+1:] + '/' + s[0:k]\n", "print(fw)\n", "print(sw)\n", "print(nw)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xs = [10,20,30,40,50,60]\n", "xs.index(30)" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "2 strategies:\n", " \n", " encrypt one letter at a time\n", " encrypt one word at a time" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['the', 'ships', 'are', 'in', 'position']\n" ] } ], "source": [ "x = \"the ships are in position\".split()\n", "print(x)" ] }, { "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }