diff --git a/Week 3_Assignment.ipynb b/Week 3_Assignment.ipynb new file mode 100644 index 0000000..936fad7 --- /dev/null +++ b/Week 3_Assignment.ipynb @@ -0,0 +1,179 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1]\n", + "[1, 1]\n", + "[1, 2, 1]\n", + "[1, 3, 3, 1]\n", + "[1, 4, 6, 4, 1]\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def ptriangle(n):\n", + " \"\"\"Pascal's triangle is an arithmetic and geometric figure first imagined by Blaise Pascal.\"\"\"\n", + " row = [1]\n", + " x = [0]\n", + " for i in range(max(n,0)):\n", + " print(row)\n", + " row = [l + r for l, r in zip(row + x, x + row)]\n", + " return n >= 1\n", + "ptriangle(5)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "black-green-red-white-yellow\n" + ] + } + ], + "source": [ + "def change(string):\n", + " return string[-1:] + string[1:-1] + string[:1]\n", + "string = [n for n in input().split('-')]\n", + "string.sort()\n", + "print('-'.join(string))" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The number 23 is not a perfect number\n" + ] + } + ], + "source": [ + "x = int(input(\"Enter number: \"))\n", + "y = 0\n", + "for i in range(1, x):\n", + " if x % i == 0:\n", + " y = y + i\n", + "if y == x:\n", + " print(f\"The number {x} is a perfect number\")\n", + "else:\n", + " print(f\"The number {x} is not a perfect number\")" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The number 28 is a perfect number\n" + ] + } + ], + "source": [ + "x = int(input(\"Enter a number: \"))\n", + "def perfect_number(n: int):\n", + " y = 0\n", + " for i in range(1, n):\n", + " if n % i == 0:\n", + " y = y + i\n", + " if y == n:\n", + " print(f\"The number {x} is a perfect number\")\n", + " else:\n", + " print(f\"The number {x} is not a perfect number\")\n", + "perfect_number(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "can only concatenate list (not \"int\") to list", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[25], line 7\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mrandom\u001b[39;00m\n\u001b[0;32m 6\u001b[0m password \u001b[39m=\u001b[39m []\n\u001b[1;32m----> 7\u001b[0m \u001b[39mfor\u001b[39;00m i \u001b[39min\u001b[39;00m \u001b[39mrange\u001b[39m(\u001b[39m1\u001b[39m, letters \u001b[39m+\u001b[39;49m \u001b[39m1\u001b[39;49m):\n\u001b[0;32m 8\u001b[0m password\u001b[39m.\u001b[39mappend(random\u001b[39m.\u001b[39mchoice(letters))\n\u001b[0;32m 9\u001b[0m \u001b[39mfor\u001b[39;00m i \u001b[39min\u001b[39;00m \u001b[39mrange\u001b[39m(\u001b[39m1\u001b[39m, symbols \u001b[39m+\u001b[39m \u001b[39m1\u001b[39m):\n", + "\u001b[1;31mTypeError\u001b[0m: can only concatenate list (not \"int\") to list" + ] + } + ], + "source": [ + "letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', ' q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y' 'z']\n", + "numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']\n", + "symbols = ['!', '@', '#', '$', '%', '^', '&', '*', '\"', '(', ')']\n", + "\n", + "import random\n", + "password = []\n", + "for i in range(1, letters + 1):\n", + " password.append(random.choice(letters))\n", + " for i in range(1, symbols + 1):\n", + " password.append(random.choice(numbers + 1))\n", + " for i in range(1, numbers + 1):\n", + " password.append(random.choice(symbols))\n", + "\n", + "random.shuffle(password)\n", + "\n", + "final_password = \"\"\n" + ] + } + ], + "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.1" + }, + "orig_nbformat": 4, + "vscode": { + "interpreter": { + "hash": "9ef3cc2511ae391cc7db93131957300bc18e82857ec78976ef34b5343338933a" + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}