From 8b9ae0f59135b3362744e0cd9dc9ac7d312545bd Mon Sep 17 00:00:00 2001 From: Aayushi Bansal Date: Sat, 6 Feb 2021 18:10:33 +0530 Subject: [PATCH 1/2] Python Assignment added --- .../LeanIn_ML_Python_assignment.ipynb | 276 ++++++++++++++++++ 1 file changed, 276 insertions(+) create mode 100644 Python-Session/Submissions/LeanIn_ML_Python_assignment.ipynb diff --git a/Python-Session/Submissions/LeanIn_ML_Python_assignment.ipynb b/Python-Session/Submissions/LeanIn_ML_Python_assignment.ipynb new file mode 100644 index 0000000..4e28f55 --- /dev/null +++ b/Python-Session/Submissions/LeanIn_ML_Python_assignment.ipynb @@ -0,0 +1,276 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "LeanIn ML Python assignment.ipynb", + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "1z5anc6RU522" + }, + "source": [ + "Name: Aayushi Bansal\r\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "yo5YKxiwVQ0i" + }, + "source": [ + "Q1. Write a function that returns the maximum of two numbers." + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "1oXandtlLear", + "outputId": "ddf3a22f-28fc-44ef-d5c4-ff183641c2aa" + }, + "source": [ + "a=int(input(\"Enter first number\"))\r\n", + "b=int(input(\"Enter second number\"))\r\n", + "def maxtwo(a,b):\r\n", + " if a>b:\r\n", + " return a\r\n", + " else:\r\n", + " return b\r\n", + "print(maxtwo(a,b))" + ], + "execution_count": 1, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Enter first number4\n", + "Enter second number8\n", + "8\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "McjOIGSPVTMY" + }, + "source": [ + "Q2. Write a function called fizz_buzz that takes a number.\r\n", + "\r\n", + "• If the number is divisible by 3, it should return “Fizz”.\r\n", + "\r\n", + "• If it is divisible by 5, it should return “Buzz”.\r\n", + "\r\n", + "• If it is divisible by both 3 and 5, it should return “FizzBuzz”.\r\n", + "\r\n", + "• Otherwise, it should return the same number." + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "sDZs6GIWL_Pu", + "outputId": "70f2146f-a1ae-4daa-8d28-d22126a3e749" + }, + "source": [ + "def fizz_buzz(n):\r\n", + " if n%3==0 and n%5==0:\r\n", + " return \"FizzBuzz\"\r\n", + " elif n%3==0:\r\n", + " return \"Fizz\"\r\n", + " elif n%5==0:\r\n", + " return \"Buzz\"\r\n", + " else:\r\n", + " return n\r\n", + "\r\n", + "n=int(input())\r\n", + "print(fizz_buzz(n))\r\n" + ], + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "text": [ + "7\n", + "7\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "d8ryWtGTVddq" + }, + "source": [ + "Q3. Write a function for checking the speed of drivers. This function should have one parameter: speed.\r\n", + "\r\n", + "• If speed is less than 70, it should print “Ok”.\r\n", + "\r\n", + "• Otherwise, for every 5km above the speed limit (70), it should give the \r\n", + "driver one demerit point and print the total number of demerit points. For\r\n", + "example, if the speed is 80, it should print: “Points: 2”.\r\n", + "\r\n", + "• If the driver gets more than 12 points, the function should print: “License \r\n", + "suspended”" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "UnS0lQK6Mt6D", + "outputId": "48769ae3-3c02-4adf-c020-137c40e63912" + }, + "source": [ + "def checkSpeed(speed):\r\n", + " if speed<70:\r\n", + " print(\"OK\")\r\n", + " else:\r\n", + " count=0\r\n", + " while speed-5>=70:\r\n", + " count+=1\r\n", + " speed-=5\r\n", + " print(\"Points: \",count)\r\n", + "\r\n", + " if count>12:\r\n", + " print(\"License Suspended\")\r\n", + "\r\n", + "s=int(input())\r\n", + "checkSpeed(s)" + ], + "execution_count": 11, + "outputs": [ + { + "output_type": "stream", + "text": [ + "200\n", + "Points: 26\n", + "License Suspended\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "IIEWpylIVnLY" + }, + "source": [ + "Q4. Write a function called showNumbers that takes a parameter called limit. It \r\n", + "should print all the numbers between 0 and limit with a label to identify the even \r\n", + "and odd numbers. For example, if the limit is 3, it should print:\r\n", + "\r\n", + "• 0 EVEN\r\n", + "\r\n", + "• 1 ODD\r\n", + "\r\n", + "• 2 EVEN\r\n", + "\r\n", + "• 3 ODD" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "lXYs1f7sOZRJ", + "outputId": "8c80bd7e-6811-4535-d9bb-1d36400887a5" + }, + "source": [ + "def showNumbers(limit):\r\n", + " for i in range(limit):\r\n", + " if i%2==0:\r\n", + " print(i,\"EVEN\")\r\n", + " else:\r\n", + " print(i, \"ODD\")\r\n", + "\r\n", + "limit=int(input())\r\n", + "showNumbers(limit)" + ], + "execution_count": 14, + "outputs": [ + { + "output_type": "stream", + "text": [ + "7\n", + "0 EVEN\n", + "1 ODD\n", + "2 EVEN\n", + "3 ODD\n", + "4 EVEN\n", + "5 ODD\n", + "6 EVEN\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "pz9250u3Vyik" + }, + "source": [ + "Q5. Write a function that returns the sum of multiples of 3 and 5 between 0 \r\n", + "and limit (parameter). For example, if limit is 20, it should return the sum of 3, 5, \r\n", + "6, 9, 10, 12, 15, 18, 20." + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "chnJM9RZQ7Hr", + "outputId": "c839a331-30b3-4242-d7ce-b1347c42a21b" + }, + "source": [ + "def sumMultiples(limit):\r\n", + " sum=0\r\n", + " if limit<3:\r\n", + " return 0\r\n", + " for i in range(3,limit+1):\r\n", + " if i%3==0 or i%5==0:\r\n", + " sum+=i\r\n", + " return sum\r\n", + "limit=int(input())\r\n", + "print(sumMultiples(limit))" + ], + "execution_count": 27, + "outputs": [ + { + "output_type": "stream", + "text": [ + "20\n", + "98\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file From 20abff0a620e03304a5d974f0f53ca43bd1d5e1e Mon Sep 17 00:00:00 2001 From: Aayushi Bansal Date: Wed, 10 Feb 2021 22:13:24 +0530 Subject: [PATCH 2/2] Changed file name --- .../Submissions/aayushibansal0021.ipynb | 276 ++++++++++++++++++ 1 file changed, 276 insertions(+) create mode 100644 Python-Session/Submissions/aayushibansal0021.ipynb diff --git a/Python-Session/Submissions/aayushibansal0021.ipynb b/Python-Session/Submissions/aayushibansal0021.ipynb new file mode 100644 index 0000000..4e28f55 --- /dev/null +++ b/Python-Session/Submissions/aayushibansal0021.ipynb @@ -0,0 +1,276 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "LeanIn ML Python assignment.ipynb", + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "1z5anc6RU522" + }, + "source": [ + "Name: Aayushi Bansal\r\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "yo5YKxiwVQ0i" + }, + "source": [ + "Q1. Write a function that returns the maximum of two numbers." + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "1oXandtlLear", + "outputId": "ddf3a22f-28fc-44ef-d5c4-ff183641c2aa" + }, + "source": [ + "a=int(input(\"Enter first number\"))\r\n", + "b=int(input(\"Enter second number\"))\r\n", + "def maxtwo(a,b):\r\n", + " if a>b:\r\n", + " return a\r\n", + " else:\r\n", + " return b\r\n", + "print(maxtwo(a,b))" + ], + "execution_count": 1, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Enter first number4\n", + "Enter second number8\n", + "8\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "McjOIGSPVTMY" + }, + "source": [ + "Q2. Write a function called fizz_buzz that takes a number.\r\n", + "\r\n", + "• If the number is divisible by 3, it should return “Fizz”.\r\n", + "\r\n", + "• If it is divisible by 5, it should return “Buzz”.\r\n", + "\r\n", + "• If it is divisible by both 3 and 5, it should return “FizzBuzz”.\r\n", + "\r\n", + "• Otherwise, it should return the same number." + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "sDZs6GIWL_Pu", + "outputId": "70f2146f-a1ae-4daa-8d28-d22126a3e749" + }, + "source": [ + "def fizz_buzz(n):\r\n", + " if n%3==0 and n%5==0:\r\n", + " return \"FizzBuzz\"\r\n", + " elif n%3==0:\r\n", + " return \"Fizz\"\r\n", + " elif n%5==0:\r\n", + " return \"Buzz\"\r\n", + " else:\r\n", + " return n\r\n", + "\r\n", + "n=int(input())\r\n", + "print(fizz_buzz(n))\r\n" + ], + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "text": [ + "7\n", + "7\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "d8ryWtGTVddq" + }, + "source": [ + "Q3. Write a function for checking the speed of drivers. This function should have one parameter: speed.\r\n", + "\r\n", + "• If speed is less than 70, it should print “Ok”.\r\n", + "\r\n", + "• Otherwise, for every 5km above the speed limit (70), it should give the \r\n", + "driver one demerit point and print the total number of demerit points. For\r\n", + "example, if the speed is 80, it should print: “Points: 2”.\r\n", + "\r\n", + "• If the driver gets more than 12 points, the function should print: “License \r\n", + "suspended”" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "UnS0lQK6Mt6D", + "outputId": "48769ae3-3c02-4adf-c020-137c40e63912" + }, + "source": [ + "def checkSpeed(speed):\r\n", + " if speed<70:\r\n", + " print(\"OK\")\r\n", + " else:\r\n", + " count=0\r\n", + " while speed-5>=70:\r\n", + " count+=1\r\n", + " speed-=5\r\n", + " print(\"Points: \",count)\r\n", + "\r\n", + " if count>12:\r\n", + " print(\"License Suspended\")\r\n", + "\r\n", + "s=int(input())\r\n", + "checkSpeed(s)" + ], + "execution_count": 11, + "outputs": [ + { + "output_type": "stream", + "text": [ + "200\n", + "Points: 26\n", + "License Suspended\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "IIEWpylIVnLY" + }, + "source": [ + "Q4. Write a function called showNumbers that takes a parameter called limit. It \r\n", + "should print all the numbers between 0 and limit with a label to identify the even \r\n", + "and odd numbers. For example, if the limit is 3, it should print:\r\n", + "\r\n", + "• 0 EVEN\r\n", + "\r\n", + "• 1 ODD\r\n", + "\r\n", + "• 2 EVEN\r\n", + "\r\n", + "• 3 ODD" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "lXYs1f7sOZRJ", + "outputId": "8c80bd7e-6811-4535-d9bb-1d36400887a5" + }, + "source": [ + "def showNumbers(limit):\r\n", + " for i in range(limit):\r\n", + " if i%2==0:\r\n", + " print(i,\"EVEN\")\r\n", + " else:\r\n", + " print(i, \"ODD\")\r\n", + "\r\n", + "limit=int(input())\r\n", + "showNumbers(limit)" + ], + "execution_count": 14, + "outputs": [ + { + "output_type": "stream", + "text": [ + "7\n", + "0 EVEN\n", + "1 ODD\n", + "2 EVEN\n", + "3 ODD\n", + "4 EVEN\n", + "5 ODD\n", + "6 EVEN\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "pz9250u3Vyik" + }, + "source": [ + "Q5. Write a function that returns the sum of multiples of 3 and 5 between 0 \r\n", + "and limit (parameter). For example, if limit is 20, it should return the sum of 3, 5, \r\n", + "6, 9, 10, 12, 15, 18, 20." + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "chnJM9RZQ7Hr", + "outputId": "c839a331-30b3-4242-d7ce-b1347c42a21b" + }, + "source": [ + "def sumMultiples(limit):\r\n", + " sum=0\r\n", + " if limit<3:\r\n", + " return 0\r\n", + " for i in range(3,limit+1):\r\n", + " if i%3==0 or i%5==0:\r\n", + " sum+=i\r\n", + " return sum\r\n", + "limit=int(input())\r\n", + "print(sumMultiples(limit))" + ], + "execution_count": 27, + "outputs": [ + { + "output_type": "stream", + "text": [ + "20\n", + "98\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file