From ef5776632bc0306195c5a8db5a8a2f7198ec3e38 Mon Sep 17 00:00:00 2001 From: Sadmankabir2084 <123572457+sadman2084@users.noreply.github.com> Date: Sun, 17 Aug 2025 19:42:46 +0600 Subject: [PATCH 1/2] Add files via upload --- 2102020.ipynb | 1643 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 1112 insertions(+), 531 deletions(-) diff --git a/2102020.ipynb b/2102020.ipynb index d39a89b..96d4220 100644 --- a/2102020.ipynb +++ b/2102020.ipynb @@ -1,531 +1,1112 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "736887bb", - "metadata": { - "id": "736887bb" - }, - "source": [ - "# Python Exercises - Easy Level\n", - "\n", - "These exercises test basic Python concepts including:\n", - "- Variables and data types\n", - "- Basic arithmetic operations\n", - "- Simple functions\n", - "- Basic conditionals\n", - "- String operations\n", - "- Lists and basic operations\n", - "\n", - "**Instructions:** Complete each exercise by writing Python code in the provided cells." - ] - }, - { - "cell_type": "markdown", - "id": "1fcc41ef", - "metadata": { - "id": "1fcc41ef" - }, - "source": [ - "## Question 1: Variables and Data Types\n", - "\n", - "Create variables for the following:\n", - "- `name` (string): Your name\n", - "- `age` (integer): Your age\n", - "- `height` (float): Your height in meters\n", - "- `is_student` (boolean): Whether you are a student\n", - "\n", - "Print each variable along with its type." - ] - }, - { - "cell_type": "code", - "execution_count": 56, - "id": "6aacf345", - "metadata": { - "id": "6aacf345" - }, - "outputs": [], - "source": [ - "name=\"Sad man\"\n", - "age=23\n", - "height=5.7\n", - "is_student=True" - ] - }, - { - "cell_type": "markdown", - "id": "2c1683e1", - "metadata": { - "id": "2c1683e1" - }, - "source": [ - "## Question 2: Basic Arithmetic\n", - "\n", - "Given two numbers `a = 15` and `b = 4`, calculate and print:\n", - "- Sum\n", - "- Difference\n", - "- Product\n", - "- True division\n", - "- Floor division\n", - "- Remainder (modulus)\n", - "- `a` raised to the power of `b`" - ] - }, - { - "cell_type": "code", - "execution_count": 57, - "id": "86d758e2", - "metadata": { - "id": "86d758e2" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "19\n", - "11\n", - "60\n", - "3.75\n", - "3\n", - "3\n", - "50625\n" - ] - } - ], - "source": [ - "a = 15\n", - "b = 4\n", - "\n", - "sm=a+b\n", - "print(sm)\n", - "dif=a-b\n", - "print(dif)\n", - "pro=a*b\n", - "print(pro)\n", - "div=a/b\n", - "print(div)\n", - "flr=a//b\n", - "print(flr)\n", - "mod=a%b\n", - "print(mod)\n", - "pwr=a**b\n", - "print(pwr)\n" - ] - }, - { - "cell_type": "markdown", - "id": "e49abb2e", - "metadata": { - "id": "e49abb2e" - }, - "source": [ - "## Question 3: Simple Function\n", - "\n", - "Write a function called `greet_user` that:\n", - "- Takes a name as a parameter\n", - "- Returns a greeting message like \"Hello, [name]!\"\n", - "- Test it with your name" - ] - }, - { - "cell_type": "code", - "execution_count": 58, - "id": "34a366ec", - "metadata": { - "id": "34a366ec" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "hello Sad man\n" - ] - } - ], - "source": [ - "def greet_user(name):\n", - " print(\"hello\",name)\n", - "\n", - "name=\"Sad man\"\n", - "greet_user(name)" - ] - }, - { - "cell_type": "markdown", - "id": "f73d26e6", - "metadata": { - "id": "f73d26e6" - }, - "source": [ - "## Question 4: Basic Conditionals\n", - "\n", - "Write a function called `check_number` that:\n", - "- Takes a number as input\n", - "- Returns \"positive\" if the number is greater than 0\n", - "- Returns \"negative\" if the number is less than 0\n", - "- Returns \"zero\" if the number equals 0\n", - "\n", - "Test with numbers: 5, -3, 0" - ] - }, - { - "cell_type": "code", - "execution_count": 59, - "id": "19ae4d41", - "metadata": { - "id": "19ae4d41" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "positive\n" - ] - } - ], - "source": [ - "def check_number(num):\n", - " if(num>0):\n", - " print(\"positive\")\n", - " elif(num<0):\n", - " print(\"negative\")\n", - " else:\n", - " print(\"zero\")\n", - "\n", - "num=int(input(\"Enter a number: \"))\n", - "check_number(num)\n" - ] - }, - { - "cell_type": "markdown", - "id": "c8b83226", - "metadata": { - "id": "c8b83226" - }, - "source": [ - "## Question 5: String Operations\n", - "\n", - "Given the string `text = \"Python Programming\"`, perform the following operations:\n", - "- Print the length of the string\n", - "- Convert to uppercase\n", - "- Convert to lowercase\n", - "- Check if it starts with \"Python\"\n", - "- Replace \"Programming\" with \"is Fun\"" - ] - }, - { - "cell_type": "code", - "execution_count": 60, - "id": "f8221848", - "metadata": { - "id": "f8221848" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "18\n", - "PYTHON PROGRAMMING\n", - "python programming\n", - "Yes, it is Python\n", - "Python fun\n" - ] - } - ], - "source": [ - "text = \"Python Programming\"\n", - "\n", - "print(len(text))\n", - "print(text.upper())\n", - "print(text.lower())\n", - "if(\"Python\" == text[:6]):\n", - " print(\"Yes, it is Python\")\n", - "\n", - "t1=text.replace(\"Programming\", \"fun\")\n", - "print(t1)\n" - ] - }, - { - "cell_type": "markdown", - "id": "61723857", - "metadata": { - "id": "61723857" - }, - "source": [ - "## Question 6: Basic Lists\n", - "\n", - "Create a list called `fruits` with the following items: \"apple\", \"banana\", \"orange\", \"grape\"\n", - "\n", - "Then:\n", - "- Print the first fruit\n", - "- Print the last fruit\n", - "- Add \"mango\" to the end of the list\n", - "- Print the length of the list\n", - "- Check if \"banana\" is in the list" - ] - }, - { - "cell_type": "code", - "execution_count": 62, - "id": "3bc3bb66", - "metadata": { - "id": "3bc3bb66" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "apple\n", - "grape\n", - "['apple', 'banana', 'orange', 'grape', 'mango']\n", - "5\n", - "yes\n" - ] - } - ], - "source": [ - "fruits=['apple','banana','orange','grape']\n", - "\n", - "print(fruits[0])\n", - "\n", - "print(fruits[-1])\n", - "\n", - "fruits.append('mango')\n", - "print(fruits)\n", - "\n", - "print(len(fruits))\n", - "i=0\n", - "while i < len(fruits):\n", - " if fruits[i] =='banana':\n", - " print(\"yes\")\n", - " break\n", - " else:\n", - " i=i+1\n" - ] - }, - { - "cell_type": "markdown", - "id": "ae8ce51f", - "metadata": { - "id": "ae8ce51f" - }, - "source": [ - "## Question 7: Simple Loop\n", - "\n", - "Write a function called `count_to_n` that:\n", - "- Takes a number `n` as input\n", - "- Prints all numbers from 1 to n (inclusive)\n", - "- Test it with n = 5" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "af9b0da0", - "metadata": { - "id": "af9b0da0" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1\n", - "2\n", - "3\n", - "4\n", - "5\n" - ] - } - ], - "source": [ - "def count_to_n(num):\n", - " i=1\n", - " while i 0):\n", + " print(\"positive\")\n", + " elif(num<0):\n", + " print(\"negative\")\n", + " else:\n", + " print(\"zero\")\n", + "\n", + "num=int(input(\"Enter a number: \"))\n", + "check_number(num)\n" + ] + }, + { + "cell_type": "markdown", + "id": "c8b83226", + "metadata": { + "id": "c8b83226" + }, + "source": [ + "## Question 5: String Operations\n", + "\n", + "Given the string `text = \"Python Programming\"`, perform the following operations:\n", + "- Print the length of the string\n", + "- Convert to uppercase\n", + "- Convert to lowercase\n", + "- Check if it starts with \"Python\"\n", + "- Replace \"Programming\" with \"is Fun\"" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "id": "f8221848", + "metadata": { + "id": "f8221848" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "18\n", + "PYTHON PROGRAMMING\n", + "python programming\n", + "Yes, it is Python\n", + "Python fun\n" + ] + } + ], + "source": [ + "text = \"Python Programming\"\n", + "\n", + "print(len(text))\n", + "print(text.upper())\n", + "print(text.lower())\n", + "if(\"Python\" == text[:6]):\n", + " print(\"Yes, it is Python\")\n", + "\n", + "t1=text.replace(\"Programming\", \"fun\")\n", + "print(t1)\n" + ] + }, + { + "cell_type": "markdown", + "id": "61723857", + "metadata": { + "id": "61723857" + }, + "source": [ + "## Question 6: Basic Lists\n", + "\n", + "Create a list called `fruits` with the following items: \"apple\", \"banana\", \"orange\", \"grape\"\n", + "\n", + "Then:\n", + "- Print the first fruit\n", + "- Print the last fruit\n", + "- Add \"mango\" to the end of the list\n", + "- Print the length of the list\n", + "- Check if \"banana\" is in the list" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "id": "3bc3bb66", + "metadata": { + "id": "3bc3bb66" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "apple\n", + "grape\n", + "['apple', 'banana', 'orange', 'grape', 'mango']\n", + "5\n", + "yes\n" + ] + } + ], + "source": [ + "fruits=['apple','banana','orange','grape']\n", + "\n", + "print(fruits[0])\n", + "\n", + "print(fruits[-1])\n", + "\n", + "fruits.append('mango')\n", + "print(fruits)\n", + "\n", + "print(len(fruits))\n", + "i=0\n", + "while i < len(fruits):\n", + " if fruits[i] =='banana':\n", + " print(\"yes\")\n", + " break\n", + " else:\n", + " i=i+1\n" + ] + }, + { + "cell_type": "markdown", + "id": "ae8ce51f", + "metadata": { + "id": "ae8ce51f" + }, + "source": [ + "## Question 7: Simple Loop\n", + "\n", + "Write a function called `count_to_n` that:\n", + "- Takes a number `n` as input\n", + "- Prints all numbers from 1 to n (inclusive)\n", + "- Test it with n = 5" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "af9b0da0", + "metadata": { + "id": "af9b0da0" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n", + "4\n", + "5\n" + ] + } + ], + "source": [ + "def count_to_n(num):\n", + " i=1\n", + " while i 3.7:\n", + " print(gpa)\n", + "\n", + " group={}\n", + " if major not in group:\n", + " group[major]=[]\n", + " group[major].append(item[\"name\"])\n", + "\n", + " print(group)\n", + "\n", + " " + ] + }, + { + "cell_type": "markdown", + "id": "58f3fcde", + "metadata": {}, + "source": [ + "## Question 10: Password Validator\n", + "\n", + "Write a function called `validate_password` that checks if a password meets these criteria:\n", + "- At least 8 characters long\n", + "- Contains at least one uppercase letter\n", + "- Contains at least one lowercase letter\n", + "- Contains at least one digit\n", + "- Contains at least one special character (!@#$%^&*)\n", + "\n", + "The function should return a dictionary with:\n", + "- \"valid\": True/False\n", + "- \"messages\": List of specific requirements that failed\n", + "\n", + "Test with passwords: \"Password123!\", \"weak\", \"NoDigits!\"" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "27ef3283", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "password choto boro vai\n", + "password e digit nai boro vai\n", + "password thik ase boro vai\n" + ] + } + ], + "source": [ + "def validate_password(password):\n", + " if len(password) < 8:\n", + " return \"password choto boro vai\"\n", + " if not any(char.isupper() for char in password):\n", + " return \"password e uppercase nai boro vai\"\n", + " if not any(char.islower() for char in password):\n", + " return \"password e lowercase nai boro vai\"\n", + " if not any(char.isdigit() for char in password):\n", + " return \"password e digit nai boro vai\"\n", + " if not any(char in \"!@#$%^&*\" for char in password):\n", + " return \"password e special character nai boro vai\"\n", + " return \"password thik ase boro vai\"\n", + "\n", + "\n", + "print(validate_password(\"weak\"))\n", + "print(validate_password(\"NoDigits!\"))\n", + "print(validate_password(\"Password123!\"))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "62f5fbb5", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "myenv", + "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.12.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +>>>>>>> 5505c4d (Add Week 01 submission – 2102020) +} From f791d2cb2632bca8f16f3a0c46e54918fd876067 Mon Sep 17 00:00:00 2001 From: Sadmankabir2084 <123572457+sadman2084@users.noreply.github.com> Date: Sun, 17 Aug 2025 19:52:04 +0600 Subject: [PATCH 2/2] Add files via upload --- 2102020.ipynb | 1692 +++++++++++++++++-------------------------------- 1 file changed, 580 insertions(+), 1112 deletions(-) diff --git a/2102020.ipynb b/2102020.ipynb index 96d4220..d6d357f 100644 --- a/2102020.ipynb +++ b/2102020.ipynb @@ -1,1112 +1,580 @@ -{ -<<<<<<< HEAD - "cells": [ - { - "cell_type": "markdown", - "id": "736887bb", - "metadata": { - "id": "736887bb" - }, - "source": [ - "# Python Exercises - Easy Level\n", - "\n", - "These exercises test basic Python concepts including:\n", - "- Variables and data types\n", - "- Basic arithmetic operations\n", - "- Simple functions\n", - "- Basic conditionals\n", - "- String operations\n", - "- Lists and basic operations\n", - "\n", - "**Instructions:** Complete each exercise by writing Python code in the provided cells." - ] - }, - { - "cell_type": "markdown", - "id": "1fcc41ef", - "metadata": { - "id": "1fcc41ef" - }, - "source": [ - "## Question 1: Variables and Data Types\n", - "\n", - "Create variables for the following:\n", - "- `name` (string): Your name\n", - "- `age` (integer): Your age\n", - "- `height` (float): Your height in meters\n", - "- `is_student` (boolean): Whether you are a student\n", - "\n", - "Print each variable along with its type." - ] - }, - { - "cell_type": "code", - "execution_count": 56, - "id": "6aacf345", - "metadata": { - "id": "6aacf345" - }, - "outputs": [], - "source": [ - "name=\"Sad man\"\n", - "age=23\n", - "height=5.7\n", - "is_student=True" - ] - }, - { - "cell_type": "markdown", - "id": "2c1683e1", - "metadata": { - "id": "2c1683e1" - }, - "source": [ - "## Question 2: Basic Arithmetic\n", - "\n", - "Given two numbers `a = 15` and `b = 4`, calculate and print:\n", - "- Sum\n", - "- Difference\n", - "- Product\n", - "- True division\n", - "- Floor division\n", - "- Remainder (modulus)\n", - "- `a` raised to the power of `b`" - ] - }, - { - "cell_type": "code", - "execution_count": 57, - "id": "86d758e2", - "metadata": { - "id": "86d758e2" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "19\n", - "11\n", - "60\n", - "3.75\n", - "3\n", - "3\n", - "50625\n" - ] - } - ], - "source": [ - "a = 15\n", - "b = 4\n", - "\n", - "sm=a+b\n", - "print(sm)\n", - "dif=a-b\n", - "print(dif)\n", - "pro=a*b\n", - "print(pro)\n", - "div=a/b\n", - "print(div)\n", - "flr=a//b\n", - "print(flr)\n", - "mod=a%b\n", - "print(mod)\n", - "pwr=a**b\n", - "print(pwr)\n" - ] - }, - { - "cell_type": "markdown", - "id": "e49abb2e", - "metadata": { - "id": "e49abb2e" - }, - "source": [ - "## Question 3: Simple Function\n", - "\n", - "Write a function called `greet_user` that:\n", - "- Takes a name as a parameter\n", - "- Returns a greeting message like \"Hello, [name]!\"\n", - "- Test it with your name" - ] - }, - { - "cell_type": "code", - "execution_count": 58, - "id": "34a366ec", - "metadata": { - "id": "34a366ec" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "hello Sad man\n" - ] - } - ], - "source": [ - "def greet_user(name):\n", - " print(\"hello\",name)\n", - "\n", - "name=\"Sad man\"\n", - "greet_user(name)" - ] - }, - { - "cell_type": "markdown", - "id": "f73d26e6", - "metadata": { - "id": "f73d26e6" - }, - "source": [ - "## Question 4: Basic Conditionals\n", - "\n", - "Write a function called `check_number` that:\n", - "- Takes a number as input\n", - "- Returns \"positive\" if the number is greater than 0\n", - "- Returns \"negative\" if the number is less than 0\n", - "- Returns \"zero\" if the number equals 0\n", - "\n", - "Test with numbers: 5, -3, 0" - ] - }, - { - "cell_type": "code", - "execution_count": 59, - "id": "19ae4d41", - "metadata": { - "id": "19ae4d41" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "positive\n" - ] - } - ], - "source": [ - "def check_number(num):\n", - " if(num>0):\n", - " print(\"positive\")\n", - " elif(num<0):\n", - " print(\"negative\")\n", - " else:\n", - " print(\"zero\")\n", - "\n", - "num=int(input(\"Enter a number: \"))\n", - "check_number(num)\n" - ] - }, - { - "cell_type": "markdown", - "id": "c8b83226", - "metadata": { - "id": "c8b83226" - }, - "source": [ - "## Question 5: String Operations\n", - "\n", - "Given the string `text = \"Python Programming\"`, perform the following operations:\n", - "- Print the length of the string\n", - "- Convert to uppercase\n", - "- Convert to lowercase\n", - "- Check if it starts with \"Python\"\n", - "- Replace \"Programming\" with \"is Fun\"" - ] - }, - { - "cell_type": "code", - "execution_count": 60, - "id": "f8221848", - "metadata": { - "id": "f8221848" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "18\n", - "PYTHON PROGRAMMING\n", - "python programming\n", - "Yes, it is Python\n", - "Python fun\n" - ] - } - ], - "source": [ - "text = \"Python Programming\"\n", - "\n", - "print(len(text))\n", - "print(text.upper())\n", - "print(text.lower())\n", - "if(\"Python\" == text[:6]):\n", - " print(\"Yes, it is Python\")\n", - "\n", - "t1=text.replace(\"Programming\", \"fun\")\n", - "print(t1)\n" - ] - }, - { - "cell_type": "markdown", - "id": "61723857", - "metadata": { - "id": "61723857" - }, - "source": [ - "## Question 6: Basic Lists\n", - "\n", - "Create a list called `fruits` with the following items: \"apple\", \"banana\", \"orange\", \"grape\"\n", - "\n", - "Then:\n", - "- Print the first fruit\n", - "- Print the last fruit\n", - "- Add \"mango\" to the end of the list\n", - "- Print the length of the list\n", - "- Check if \"banana\" is in the list" - ] - }, - { - "cell_type": "code", - "execution_count": 62, - "id": "3bc3bb66", - "metadata": { - "id": "3bc3bb66" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "apple\n", - "grape\n", - "['apple', 'banana', 'orange', 'grape', 'mango']\n", - "5\n", - "yes\n" - ] - } - ], - "source": [ - "fruits=['apple','banana','orange','grape']\n", - "\n", - "print(fruits[0])\n", - "\n", - "print(fruits[-1])\n", - "\n", - "fruits.append('mango')\n", - "print(fruits)\n", - "\n", - "print(len(fruits))\n", - "i=0\n", - "while i < len(fruits):\n", - " if fruits[i] =='banana':\n", - " print(\"yes\")\n", - " break\n", - " else:\n", - " i=i+1\n" - ] - }, - { - "cell_type": "markdown", - "id": "ae8ce51f", - "metadata": { - "id": "ae8ce51f" - }, - "source": [ - "## Question 7: Simple Loop\n", - "\n", - "Write a function called `count_to_n` that:\n", - "- Takes a number `n` as input\n", - "- Prints all numbers from 1 to n (inclusive)\n", - "- Test it with n = 5" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "af9b0da0", - "metadata": { - "id": "af9b0da0" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1\n", - "2\n", - "3\n", - "4\n", - "5\n" - ] - } - ], - "source": [ - "def count_to_n(num):\n", - " i=1\n", - " while i 3.7:\n", - " print(gpa)\n", - "\n", - " group={}\n", - " if major not in group:\n", - " group[major]=[]\n", - " group[major].append(item[\"name\"])\n", - "\n", - " print(group)\n", - "\n", - " " - ] - }, - { - "cell_type": "markdown", - "id": "58f3fcde", - "metadata": {}, - "source": [ - "## Question 10: Password Validator\n", - "\n", - "Write a function called `validate_password` that checks if a password meets these criteria:\n", - "- At least 8 characters long\n", - "- Contains at least one uppercase letter\n", - "- Contains at least one lowercase letter\n", - "- Contains at least one digit\n", - "- Contains at least one special character (!@#$%^&*)\n", - "\n", - "The function should return a dictionary with:\n", - "- \"valid\": True/False\n", - "- \"messages\": List of specific requirements that failed\n", - "\n", - "Test with passwords: \"Password123!\", \"weak\", \"NoDigits!\"" - ] - }, - { - "cell_type": "code", - "execution_count": 40, - "id": "27ef3283", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "password choto boro vai\n", - "password e digit nai boro vai\n", - "password thik ase boro vai\n" - ] - } - ], - "source": [ - "def validate_password(password):\n", - " if len(password) < 8:\n", - " return \"password choto boro vai\"\n", - " if not any(char.isupper() for char in password):\n", - " return \"password e uppercase nai boro vai\"\n", - " if not any(char.islower() for char in password):\n", - " return \"password e lowercase nai boro vai\"\n", - " if not any(char.isdigit() for char in password):\n", - " return \"password e digit nai boro vai\"\n", - " if not any(char in \"!@#$%^&*\" for char in password):\n", - " return \"password e special character nai boro vai\"\n", - " return \"password thik ase boro vai\"\n", - "\n", - "\n", - "print(validate_password(\"weak\"))\n", - "print(validate_password(\"NoDigits!\"))\n", - "print(validate_password(\"Password123!\"))\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "62f5fbb5", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "myenv", - "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.12.10" - } - }, - "nbformat": 4, - "nbformat_minor": 5 ->>>>>>> 5505c4d (Add Week 01 submission – 2102020) -} +{ + "cells": [ + { + "cell_type": "markdown", + "id": "58f3c807", + "metadata": {}, + "source": [ + "# Python Exercises - Medium Level\n", + "\n", + "These exercises test intermediate Python concepts including:\n", + "- Functions with multiple parameters and return values\n", + "- List comprehensions\n", + "- Dictionary operations\n", + "- Advanced string manipulation\n", + "- Nested loops and conditionals\n", + "- Working with multiple data structures\n", + "\n", + "**Instructions:** Complete each exercise by writing Python code in the provided cells." + ] + }, + { + "cell_type": "markdown", + "id": "2eaf75cb", + "metadata": {}, + "source": [ + "## Question 1: Function with Multiple Return Values\n", + "\n", + "Write a function called `analyze_numbers` that:\n", + "- Takes a list of numbers as input\n", + "- Returns a tuple containing: (sum, average, maximum, minimum)\n", + "- Test with the list: [4, 7, 2, 9, 1, 6, 8, 3]" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "beb2582b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The numbers are: [4, 7, 2, 9, 1, 6, 8, 3]\n", + "sum is 40\n", + "max is 9\n", + "min is 1\n", + "avg is 5.0\n" + ] + } + ], + "source": [ + "# Your code here\n", + "def analyze_numbers(numbers):\n", + " number=tuple(numbers)\n", + " print(\"The numbers are:\", numbers)\n", + " print('sum is ',sum(numbers))\n", + " print('max is ', max(numbers))\n", + " print('min is ', min(numbers))\n", + " print('avg is ', sum(numbers)/len(numbers))\n", + " \n", + "\n", + "lt=[4,7,2,9,1,6,8,3]\n", + "analyze_numbers(lt)" + ] + }, + { + "cell_type": "markdown", + "id": "32aa97ad", + "metadata": {}, + "source": [ + "## Question 2: List Comprehension Challenge\n", + "\n", + "Given the list `numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]`, create the following using list comprehensions:\n", + "- A list of squares of all even numbers\n", + "- A list of numbers divisible by 3\n", + "- A list of strings saying \"[number] is odd\" for odd numbers only" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "8745c171", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "number are odd 1\n", + "squares are 4\n", + "number are odd 3\n", + "divisible by 3 3\n", + "squares are 16\n", + "number are odd 5\n", + "squares are 36\n", + "divisible by 3 6\n", + "number are odd 7\n", + "squares are 64\n", + "number are odd 9\n", + "divisible by 3 9\n", + "squares are 100\n" + ] + } + ], + "source": [ + "numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n", + "\n", + "# Your code here\n", + "i=0\n", + "while i < len(numbers):\n", + " if numbers[i] % 2 == 0:\n", + " print('squares are ', numbers[i] ** 2)\n", + " else:\n", + " print(\"number are odd \", numbers[i])\n", + " if numbers[i] % 3 == 0:\n", + " print(\"divisible by 3 \",numbers[i])\n", + "\n", + " i += 1" + ] + }, + { + "cell_type": "markdown", + "id": "e21948e9", + "metadata": {}, + "source": [ + "## Question 3: Dictionary Operations\n", + "\n", + "Create a dictionary called `student_grades` with the following data:\n", + "- \"Alice\": [85, 90, 78, 92]\n", + "- \"Bob\": [76, 88, 81, 79]\n", + "- \"Charlie\": [92, 95, 87, 91]\n", + "\n", + "Write a function that:\n", + "- Calculates the average grade for each student\n", + "- Returns a new dictionary with student names as keys and average grades as values\n", + "- Finds and prints the student with the highest average" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b1f8c090", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "91.25\n" + ] + }, + { + "data": { + "text/plain": [ + "{'Alice': 86.25, 'Bob': 81.0, 'Charlie': 91.25}" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Your code here\n", + "student_grades = {\"Alice\": [85, 90, 78, 92], \"Bob\": [76, 88, 81, 79], \"Charlie\": [92, 95, 87, 91]}\n", + "\n", + "def analyze_student_grades(grades):\n", + "\n", + " avg={}\n", + "\n", + " for student,grades in student_grades.items():\n", + " avg[student]=sum(grades)/len(grades)\n", + " # print(avg)\n", + " top=max(avg,key=avg.get)\n", + " print(\"max avg\",avg[top])\n", + " return avg\n", + "analyze_student_grades(student_grades)" + ] + }, + { + "cell_type": "markdown", + "id": "34bc3073", + "metadata": {}, + "source": [ + "## Question 4: String Processing\n", + "\n", + "Write a function called `word_frequency` that:\n", + "- Takes a sentence as input\n", + "- Returns a dictionary with each word as a key and its frequency as the value\n", + "- Words should be case-insensitive\n", + "- Test with: \"The quick brown fox jumps over the lazy dog the dog was lazy\"" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "245662f1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'the': 3, 'quick': 1, 'brown': 1, 'fox': 1, 'jumps': 1, 'over': 1, 'lazy': 2, 'dog': 2, 'was': 1}\n" + ] + } + ], + "source": [ + "# Your code here\n", + "def word_frequency():\n", + " text=input(\"Enter a string: \").lower().split()\n", + "\n", + " frq={}\n", + " for word in text:\n", + " if word in frq:\n", + " frq[word]+=1\n", + " else:\n", + " frq[word]=1\n", + "\n", + " return frq\n", + "\n", + "print(word_frequency())" + ] + }, + { + "cell_type": "markdown", + "id": "fc1dcd37", + "metadata": {}, + "source": [ + "## Question 5: Nested Loops and Pattern\n", + "\n", + "Write a function called `multiplication_table` that:\n", + "- Takes a number `n` as input\n", + "- Prints a multiplication table from 1 to n\n", + "- Format the output nicely with proper alignment\n", + "- Test with n = 5" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "9305e600", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5 x 1 = 5\n", + "5 x 2 = 10\n", + "5 x 3 = 15\n", + "5 x 4 = 20\n" + ] + } + ], + "source": [ + "# Your code here\n", + "def multiplication_table(n):\n", + " table=[]\n", + " for i in range(1,n):\n", + " table.append(n*i)\n", + " print(f\"{n} x {i} = {n*i}\")\n", + " i+=1\n", + "\n", + "n=int(input(\"Enter a number: \"))\n", + "multiplication_table(n)\n", + " " + ] + }, + { + "cell_type": "markdown", + "id": "b9ba0917", + "metadata": {}, + "source": [ + "## Question 6: List Manipulation\n", + "\n", + "Write a function called `remove_duplicates` that:\n", + "- Takes a list as input\n", + "- Returns a new list with duplicates removed while preserving the original order\n", + "- Don't use the set() function\n", + "- Test with: [1, 2, 2, 3, 4, 4, 5, 1, 6]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "725abfbc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 6]\n" + ] + } + ], + "source": [ + "# Your code here\n", + "def remove_duplicates(lst):\n", + " unq=[]\n", + " for i in lst:\n", + " if i not in unq:\n", + " unq.append(i)\n", + " return unq\n", + "lst=map(int,input(\"enter numbers: \").split(','))\n", + "print(remove_duplicates(lst))\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "fabb21b6", + "metadata": {}, + "source": [ + "## Question 7: Advanced String Formatting\n", + "\n", + "Given the following data about products:\n", + "```python\n", + "products = [\n", + " {\"name\": \"Laptop\", \"price\": 999.99, \"quantity\": 5},\n", + " {\"name\": \"Mouse\", \"price\": 25.50, \"quantity\": 20},\n", + " {\"name\": \"Keyboard\", \"price\": 75.00, \"quantity\": 15}\n", + "]\n", + "```\n", + "\n", + "Create a formatted report that shows:\n", + "- Product name\n", + "- Price\n", + "- Quantity\n", + "- Total value (price × quantity, right-aligned, 2 decimal places)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "cb37822a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "product name Laptop corresponding price 999.99 quantity 5 total value 4999.95\n", + "product name Mouse corresponding price 25.5 quantity 20 total value 510.0\n", + "product name Keyboard corresponding price 75.0 quantity 15 total value 1125.0\n" + ] + } + ], + "source": [ + "products = [\n", + " {\"name\": \"Laptop\", \"price\": 999.99, \"quantity\": 5},\n", + " {\"name\": \"Mouse\", \"price\": 25.50, \"quantity\": 20},\n", + " {\"name\": \"Keyboard\", \"price\": 75.00, \"quantity\": 15}\n", + "]\n", + "\n", + "# Your code here\n", + "for itm in products:\n", + " product=itm[\"name\"]\n", + " price=itm[\"price\"]\n", + " quantity=itm['quantity']\n", + "\n", + " total_value = price * quantity\n", + " print(f\"product name {product} corresponding price {price} quantity {quantity} total value {total_value}\")" + ] + }, + { + "cell_type": "markdown", + "id": "f2458f23", + "metadata": {}, + "source": [ + "## Question 8: Function as Parameter\n", + "\n", + "Write a function called `apply_operation` that:\n", + "- Takes a list of numbers and a function as parameters\n", + "- Applies the function to each number in the list\n", + "- Returns a new list with the results\n", + "\n", + "Then create two simple functions:\n", + "- `square(x)`: returns x squared\n", + "- `cube(x)`: returns x cubed\n", + "\n", + "Test `apply_operation` with both functions using the list [1, 2, 3, 4, 5]" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "e6694ca2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16, 25, 6084, 36, 64]\n", + "[1, 8, 27, 64, 125, 474552, 216, 512]\n" + ] + } + ], + "source": [ + "# Your code here\n", + "def apply_operation(num,func):\n", + " result =[]\n", + " for i in num:\n", + " result.append(func(i))\n", + " return result\n", + "\n", + "def square(x):\n", + " return x * x\n", + "\n", + "def cube(x):\n", + " return x * x * x\n", + "\n", + "\n", + "num=[1,2,3,4,5,78,6,8]\n", + "print(apply_operation(num,square))\n", + "print(apply_operation(num,cube))" + ] + }, + { + "cell_type": "markdown", + "id": "501a6617", + "metadata": {}, + "source": [ + "## Question 9: Data Processing Challenge\n", + "\n", + "Given a list of dictionaries representing students:\n", + "```python\n", + "students = [\n", + " {\"name\": \"Alice\", \"age\": 20, \"major\": \"Computer Science\", \"gpa\": 3.8},\n", + " {\"name\": \"Bob\", \"age\": 19, \"major\": \"Mathematics\", \"gpa\": 3.6},\n", + " {\"name\": \"Charlie\", \"age\": 21, \"major\": \"Computer Science\", \"gpa\": 3.9},\n", + " {\"name\": \"Diana\", \"age\": 20, \"major\": \"Physics\", \"gpa\": 3.7}\n", + "]\n", + "```\n", + "\n", + "Write functions to:\n", + "1. Find all students with GPA above 3.7\n", + "2. Group students by major\n", + "3. Find the average age of students in each major" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d30a94a9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3.8\n", + "{'Computer Science': ['Alice']}\n", + "{'Mathematics': ['Bob']}\n", + "3.9\n", + "{'Computer Science': ['Charlie']}\n", + "{'Physics': ['Diana']}\n" + ] + } + ], + "source": [ + "students = [\n", + " {\"name\": \"Alice\", \"age\": 20, \"major\": \"Computer Science\", \"gpa\": 3.8},\n", + " {\"name\": \"Bob\", \"age\": 19, \"major\": \"Mathematics\", \"gpa\": 3.6},\n", + " {\"name\": \"Charlie\", \"age\": 21, \"major\": \"Computer Science\", \"gpa\": 3.9},\n", + " {\"name\": \"Diana\", \"age\": 20, \"major\": \"Physics\", \"gpa\": 3.7}\n", + "]\n", + "\n", + "# Your code here\n", + "for item in students:\n", + " name=item['name']\n", + " age=item['age']\n", + " major=item['major']\n", + " gpa=item['gpa']\n", + " if gpa > 3.7:\n", + " print(gpa)\n", + "\n", + " group={}\n", + " if major not in group:\n", + " group[major]=[]\n", + " group[major].append(item[\"name\"])\n", + "\n", + " print(group)\n", + "\n", + " " + ] + }, + { + "cell_type": "markdown", + "id": "58f3fcde", + "metadata": {}, + "source": [ + "## Question 10: Password Validator\n", + "\n", + "Write a function called `validate_password` that checks if a password meets these criteria:\n", + "- At least 8 characters long\n", + "- Contains at least one uppercase letter\n", + "- Contains at least one lowercase letter\n", + "- Contains at least one digit\n", + "- Contains at least one special character (!@#$%^&*)\n", + "\n", + "The function should return a dictionary with:\n", + "- \"valid\": True/False\n", + "- \"messages\": List of specific requirements that failed\n", + "\n", + "Test with passwords: \"Password123!\", \"weak\", \"NoDigits!\"" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "27ef3283", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "password choto boro vai\n", + "password e digit nai boro vai\n", + "password thik ase boro vai\n" + ] + } + ], + "source": [ + "def validate_password(password):\n", + " if len(password) < 8:\n", + " return \"password choto boro vai\"\n", + " if not any(char.isupper() for char in password):\n", + " return \"password e uppercase nai boro vai\"\n", + " if not any(char.islower() for char in password):\n", + " return \"password e lowercase nai boro vai\"\n", + " if not any(char.isdigit() for char in password):\n", + " return \"password e digit nai boro vai\"\n", + " if not any(char in \"!@#$%^&*\" for char in password):\n", + " return \"password e special character nai boro vai\"\n", + " return \"password thik ase boro vai\"\n", + "\n", + "\n", + "print(validate_password(\"weak\"))\n", + "print(validate_password(\"NoDigits!\"))\n", + "print(validate_password(\"Password123!\"))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "62f5fbb5", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "myenv", + "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.12.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}