From 5bfaffdaec3456367ac52f56b56a1873e00e381b Mon Sep 17 00:00:00 2001 From: mhmtnzly Date: Sun, 26 Sep 2021 00:09:59 +0200 Subject: [PATCH 01/12] First --- perfect_numbers.ipynb | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 perfect_numbers.ipynb diff --git a/perfect_numbers.ipynb b/perfect_numbers.ipynb new file mode 100644 index 0000000..ca9eb3f --- /dev/null +++ b/perfect_numbers.ipynb @@ -0,0 +1,47 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Perfect number: Perfect number is a positive integer that is equal to the sum of its proper divisors.\n", + "\n", + "* The smallest perfect number is 6, which is the sum of 1, 2, and 3.\n", + "\n", + "* Some other perfect numbers are 28(1+2+4+7+14=28), 496 and 8128.\n", + "\n", + "* Write a function that finds perfect numbers between 1 and 1000. Check perfect numbers between 1 and 1000 and find the sum of the perfect numbers using reduce and filter functions." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "list(lambda x: x+1,range(1,1000))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.8.5 64-bit ('base': conda)", + "name": "python385jvsc74a57bd0054e6073c53ecefb2cc966210e656e13c3a3c774a68778f6cdf25d7c37e20456" + }, + "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" + }, + "orig_nbformat": 2 + }, + "nbformat": 4, + "nbformat_minor": 2 +} \ No newline at end of file From b42e5ae710b5d8f654be2ca0e0f250c4b9b8387d Mon Sep 17 00:00:00 2001 From: mhmtnzly Date: Sun, 26 Sep 2021 00:54:37 +0200 Subject: [PATCH 02/12] Third --- alphabetical_order.ipynb | 61 ++++++++++++++++++++++++++++++ perfect_numbers.ipynb | 47 ++++++++++++++++++++++- reading_numbers.ipynb | 82 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 alphabetical_order.ipynb create mode 100644 reading_numbers.ipynb diff --git a/alphabetical_order.ipynb b/alphabetical_order.ipynb new file mode 100644 index 0000000..00abfb9 --- /dev/null +++ b/alphabetical_order.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Write a function that takes an input of different words with hyphen (-) in between them and then:
\n", + "* sorts the words in alphabetical order,\n", + "* adds hyphen icon (-) between them, \n", + "* gives the output of the sorted words.\n", + "\n", + "* Example:\n", + "* Input >>> green-red-yellow-black-white\n", + "* Output >>> black-green-red-white-yellow " + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['black', 'green', 'red', 'white', 'yellow']\n" + ] + } + ], + "source": [ + "def alphabetical_order():\n", + " words=input(\"Words with - : \")\n", + " words=words.split('-')\n", + " words.sort()\n", + " return words\n", + "print(alphabetical_order())" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.8.5 64-bit ('base': conda)", + "name": "python385jvsc74a57bd0054e6073c53ecefb2cc966210e656e13c3a3c774a68778f6cdf25d7c37e20456" + }, + "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" + }, + "orig_nbformat": 2 + }, + "nbformat": 4, + "nbformat_minor": 2 +} \ No newline at end of file diff --git a/perfect_numbers.ipynb b/perfect_numbers.ipynb index ca9eb3f..dac132c 100644 --- a/perfect_numbers.ipynb +++ b/perfect_numbers.ipynb @@ -15,11 +15,54 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ - "list(lambda x: x+1,range(1,1000))" + "def perfect_number(x):\n", + " summ=0\n", + " for i in range(1,x):\n", + " if x%i==0:\n", + " summ+=i\n", + " if summ==x:\n", + " return True" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": "[6, 28, 496]" + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from functools import reduce\n", + "list(filter(lambda x: perfect_number(x),range(1,1000)))" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": "530" + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "reduce(lambda a,b:a+b,(list(filter(lambda x: perfect_number(x),range(1,1000)))))" ] } ], diff --git a/reading_numbers.ipynb b/reading_numbers.ipynb new file mode 100644 index 0000000..35527d4 --- /dev/null +++ b/reading_numbers.ipynb @@ -0,0 +1,82 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Write a function that outputs the transcription of an input number with two digits.\n", + "\n", + "* Example:\n", + "\n", + "* 28---------------->Twenty Eight" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "reading1=['','One','Two','Three','Four','Five','Six','Seven','Eight','Nine']\n", + "reading2=['Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety']\n", + "reading3=['Ten','Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Nineteen']\n", + "def reading_numb(x):\n", + " if x.isdigit()==False:\n", + " read= x\n", + " elif int(x)<10 or int(x)>99:\n", + " read= x\n", + " elif 20>int(x)>=10:\n", + " read='{}--------->{}'.format(x,reading3[int(x[1])])\n", + " \n", + " else:\n", + " read='{}--------->{} {}'.format(x,reading2[int(x[0])-2],reading1[int(x[1])])\n", + " return read\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "29--------->Twenty Nine\n" + ] + } + ], + "source": [ + "print(reading_numb(input(\"A number only with two digits: \")))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.8.5 64-bit ('base': conda)", + "name": "python385jvsc74a57bd0054e6073c53ecefb2cc966210e656e13c3a3c774a68778f6cdf25d7c37e20456" + }, + "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" + }, + "orig_nbformat": 2 + }, + "nbformat": 4, + "nbformat_minor": 2 +} \ No newline at end of file From 29f297b992b0dfe69c5ed9cd3aeb3ff055ce2683 Mon Sep 17 00:00:00 2001 From: mhmtnzly Date: Sun, 26 Sep 2021 01:02:44 +0200 Subject: [PATCH 03/12] forth --- unique_list.ipynb | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 unique_list.ipynb diff --git a/unique_list.ipynb b/unique_list.ipynb new file mode 100644 index 0000000..3dcd47d --- /dev/null +++ b/unique_list.ipynb @@ -0,0 +1,64 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "* Write a function that filters all the unique(unrepeated) elements of a given list.\n", + "\n", + "* Example:\n", + "```\n", + "* Function call: unique_list([1,2,3,3,3,3,4,5,5])\n", + "* Output : [1, 2, 3, 4, 5]" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n" + ] + } + ], + "source": [ + "print(1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.8.5 64-bit ('base': conda)", + "name": "python385jvsc74a57bd0054e6073c53ecefb2cc966210e656e13c3a3c774a68778f6cdf25d7c37e20456" + }, + "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" + }, + "orig_nbformat": 2 + }, + "nbformat": 4, + "nbformat_minor": 2 +} \ No newline at end of file From b737c66f1d549359b4db3a70c169b581cd038e0d Mon Sep 17 00:00:00 2001 From: mhmtnzly Date: Sun, 26 Sep 2021 01:14:44 +0200 Subject: [PATCH 04/12] fifth --- equal_reverse.ipynb | 83 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 equal_reverse.ipynb diff --git a/equal_reverse.ipynb b/equal_reverse.ipynb new file mode 100644 index 0000000..abee06e --- /dev/null +++ b/equal_reverse.ipynb @@ -0,0 +1,83 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "* Write a function that controls the given inputs whether they are equal to their reversed order or not.\n", + "* Example:\n", + "* Input >>> madam, tacocat, utrecht \n", + "* Output >>> True, True, False" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": "[True, True, False]" + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(map(lambda x: x==x[::-1],['madam','tacocat','utrecht']))" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": "[True, True, False]" + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def reserved(x):\n", + " if x==x[::-1]:\n", + " return True\n", + " else:\n", + " return False\n", + "list(map(lambda x: reserved(x),['madam','tacocat','utrecht']))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.8.5 64-bit ('base': conda)", + "name": "python385jvsc74a57bd0054e6073c53ecefb2cc966210e656e13c3a3c774a68778f6cdf25d7c37e20456" + }, + "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" + }, + "orig_nbformat": 2 + }, + "nbformat": 4, + "nbformat_minor": 2 +} \ No newline at end of file From 08743e8b3fd5a21ca80ca557210d4b23efa172ac Mon Sep 17 00:00:00 2001 From: mhmtnzly Date: Sun, 26 Sep 2021 01:50:39 +0200 Subject: [PATCH 05/12] Last --- bonus-hacherrank.ipynb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 bonus-hacherrank.ipynb diff --git a/bonus-hacherrank.ipynb b/bonus-hacherrank.ipynb new file mode 100644 index 0000000..11f80e1 --- /dev/null +++ b/bonus-hacherrank.ipynb @@ -0,0 +1,24 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.8.5 64-bit ('base': conda)", + "name": "python385jvsc74a57bd0054e6073c53ecefb2cc966210e656e13c3a3c774a68778f6cdf25d7c37e20456" + }, + "language_info": { + "name": "python", + "version": "" + }, + "orig_nbformat": 2 + }, + "nbformat": 4, + "nbformat_minor": 2 +} \ No newline at end of file From ea7372dd41de990045561495908745dde8f1d5de Mon Sep 17 00:00:00 2001 From: mhmtnzly Date: Sun, 26 Sep 2021 15:01:40 +0200 Subject: [PATCH 06/12] add join --- alphabetical_order.ipynb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/alphabetical_order.ipynb b/alphabetical_order.ipynb index 00abfb9..41feed0 100644 --- a/alphabetical_order.ipynb +++ b/alphabetical_order.ipynb @@ -16,14 +16,14 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "['black', 'green', 'red', 'white', 'yellow']\n" + "black-green-red-white-yellow\n" ] } ], @@ -32,9 +32,17 @@ " words=input(\"Words with - : \")\n", " words=words.split('-')\n", " words.sort()\n", + " words='-'.join(words)\n", " return words\n", "print(alphabetical_order())" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { From afe8d1188e73ebcc0e5d68b27f80621628a1cabe Mon Sep 17 00:00:00 2001 From: mhmtnzly Date: Sun, 26 Sep 2021 15:13:46 +0200 Subject: [PATCH 07/12] last --- reading_numbers.ipynb | 42 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/reading_numbers.ipynb b/reading_numbers.ipynb index 35527d4..46e00f1 100644 --- a/reading_numbers.ipynb +++ b/reading_numbers.ipynb @@ -13,14 +13,23 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "99--------->Ninety Nine\n" + ] + } + ], "source": [ "reading1=['','One','Two','Three','Four','Five','Six','Seven','Eight','Nine']\n", "reading2=['Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety']\n", "reading3=['Ten','Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Nineteen']\n", - "def reading_numb(x):\n", + "def reading_numb():\n", + " x=input(\"A number only with two digits: \")\n", " if x.isdigit()==False:\n", " read= x\n", " elif int(x)<10 or int(x)>99:\n", @@ -30,32 +39,9 @@ " \n", " else:\n", " read='{}--------->{} {}'.format(x,reading2[int(x[0])-2],reading1[int(x[1])])\n", - " return read\n" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "29--------->Twenty Nine\n" - ] - } - ], - "source": [ - "print(reading_numb(input(\"A number only with two digits: \")))" + " return read\n", + "print(reading_numb())\n" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { From 469b48927810c493c8088b62bd3176e8dcd81886 Mon Sep 17 00:00:00 2001 From: mhmtnzly Date: Sun, 26 Sep 2021 15:37:42 +0200 Subject: [PATCH 08/12] last --- equal_reverse.ipynb | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/equal_reverse.ipynb b/equal_reverse.ipynb index abee06e..2278166 100644 --- a/equal_reverse.ipynb +++ b/equal_reverse.ipynb @@ -12,20 +12,20 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ { "data": { - "text/plain": "[True, True, False]" + "text/plain": "[True, True, False, True]" }, - "execution_count": 7, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "list(map(lambda x: x==x[::-1],['madam','tacocat','utrecht']))" + "list(map(lambda x: x==x[::-1],['madam','tacocat','utrecht','ada']))" ] }, { @@ -48,15 +48,8 @@ " return True\n", " else:\n", " return False\n", - "list(map(lambda x: reserved(x),['madam','tacocat','utrecht']))" + "list(map(lambda x: reserved(x),['madam','tacocat','utrecht','ada']))" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { From 2f5cd24c010f8fb984c4729deacff57f40bd4c5b Mon Sep 17 00:00:00 2001 From: mhmtnzly Date: Sun, 26 Sep 2021 15:38:34 +0200 Subject: [PATCH 09/12] v.02 --- bonus-hacherrank.ipynb | 67 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/bonus-hacherrank.ipynb b/bonus-hacherrank.ipynb index 11f80e1..fbbf09a 100644 --- a/bonus-hacherrank.ipynb +++ b/bonus-hacherrank.ipynb @@ -1,11 +1,64 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Bonus Question 1\n", + "[HACKERRANK: FIND DIGITS](https://www.hackerrank.com/challenges/find-digits/problem)" + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def findDigits(n):\n", + " n=str(n)\n", + " l=len(n)\n", + " summ=0\n", + " for i in range(l):\n", + " if int(n[i])==0:\n", + " continue\n", + " elif int(n)%int(n[i])==0:\n", + " summ+=1\n", + " return summ" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Bonus Question 2\n", + "[HACKERRANK: CAPITALIZE](https://www.hackerrank.com/challenges/capitalize/problem)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": "'Chris Alan'" + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def solve(s):\n", + " s=s.split(' ')\n", + " for i in range(len(s)):\n", + " if s[i]=='':\n", + " continue\n", + " s[i]=s[i][0].capitalize()+s[i][1:]\n", + " s=' '.join([str(item) for item in s])\n", + " return s\n", + "solve('chris alan')" + ] } ], "metadata": { @@ -14,8 +67,16 @@ "name": "python385jvsc74a57bd0054e6073c53ecefb2cc966210e656e13c3a3c774a68778f6cdf25d7c37e20456" }, "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", "name": "python", - "version": "" + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.5" }, "orig_nbformat": 2 }, From 89bd65fb64682c45436b78da39c4334c009736ba Mon Sep 17 00:00:00 2001 From: mhmtnzly Date: Sun, 26 Sep 2021 15:46:50 +0200 Subject: [PATCH 10/12] v.02 --- unique_list.ipynb | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/unique_list.ipynb b/unique_list.ipynb index 3dcd47d..83998df 100644 --- a/unique_list.ipynb +++ b/unique_list.ipynb @@ -1,35 +1,41 @@ { "cells": [ { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ "\n", "* Write a function that filters all the unique(unrepeated) elements of a given list.\n", "\n", "* Example:\n", - "```\n", "* Function call: unique_list([1,2,3,3,3,3,4,5,5])\n", "* Output : [1, 2, 3, 4, 5]" ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 7, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "1\n" - ] + "data": { + "text/plain": "[1, 2, 3, 4, 5]" + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "print(1)" + "def unique_list(list):\n", + " new_list=[]\n", + " for i in list:\n", + " if i in new_list:\n", + " continue\n", + " else:\n", + " new_list.append(i)\n", + " return new_list\n", + "unique_list([1,2,3,3,3,3,4,5,5])" ] }, { From 1df94a2a49f27b935d1b7d87951107f3d2ce0386 Mon Sep 17 00:00:00 2001 From: mhmtnzly Date: Sun, 10 Oct 2021 01:03:15 +0200 Subject: [PATCH 11/12] Deleted the file from the git repository --- alphabetical_order.ipynb | 69 ------------------------------ bonus-hacherrank.ipynb | 85 ------------------------------------- equal_reverse.ipynb | 76 --------------------------------- perfect_numbers.ipynb | 90 ---------------------------------------- reading_numbers.ipynb | 68 ------------------------------ unique_list.ipynb | 70 ------------------------------- 6 files changed, 458 deletions(-) delete mode 100644 alphabetical_order.ipynb delete mode 100644 bonus-hacherrank.ipynb delete mode 100644 equal_reverse.ipynb delete mode 100644 perfect_numbers.ipynb delete mode 100644 reading_numbers.ipynb delete mode 100644 unique_list.ipynb diff --git a/alphabetical_order.ipynb b/alphabetical_order.ipynb deleted file mode 100644 index 41feed0..0000000 --- a/alphabetical_order.ipynb +++ /dev/null @@ -1,69 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* Write a function that takes an input of different words with hyphen (-) in between them and then:
\n", - "* sorts the words in alphabetical order,\n", - "* adds hyphen icon (-) between them, \n", - "* gives the output of the sorted words.\n", - "\n", - "* Example:\n", - "* Input >>> green-red-yellow-black-white\n", - "* Output >>> black-green-red-white-yellow " - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "black-green-red-white-yellow\n" - ] - } - ], - "source": [ - "def alphabetical_order():\n", - " words=input(\"Words with - : \")\n", - " words=words.split('-')\n", - " words.sort()\n", - " words='-'.join(words)\n", - " return words\n", - "print(alphabetical_order())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3.8.5 64-bit ('base': conda)", - "name": "python385jvsc74a57bd0054e6073c53ecefb2cc966210e656e13c3a3c774a68778f6cdf25d7c37e20456" - }, - "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" - }, - "orig_nbformat": 2 - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file diff --git a/bonus-hacherrank.ipynb b/bonus-hacherrank.ipynb deleted file mode 100644 index fbbf09a..0000000 --- a/bonus-hacherrank.ipynb +++ /dev/null @@ -1,85 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Bonus Question 1\n", - "[HACKERRANK: FIND DIGITS](https://www.hackerrank.com/challenges/find-digits/problem)" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "def findDigits(n):\n", - " n=str(n)\n", - " l=len(n)\n", - " summ=0\n", - " for i in range(l):\n", - " if int(n[i])==0:\n", - " continue\n", - " elif int(n)%int(n[i])==0:\n", - " summ+=1\n", - " return summ" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Bonus Question 2\n", - "[HACKERRANK: CAPITALIZE](https://www.hackerrank.com/challenges/capitalize/problem)" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": "'Chris Alan'" - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def solve(s):\n", - " s=s.split(' ')\n", - " for i in range(len(s)):\n", - " if s[i]=='':\n", - " continue\n", - " s[i]=s[i][0].capitalize()+s[i][1:]\n", - " s=' '.join([str(item) for item in s])\n", - " return s\n", - "solve('chris alan')" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3.8.5 64-bit ('base': conda)", - "name": "python385jvsc74a57bd0054e6073c53ecefb2cc966210e656e13c3a3c774a68778f6cdf25d7c37e20456" - }, - "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" - }, - "orig_nbformat": 2 - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file diff --git a/equal_reverse.ipynb b/equal_reverse.ipynb deleted file mode 100644 index 2278166..0000000 --- a/equal_reverse.ipynb +++ /dev/null @@ -1,76 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* Write a function that controls the given inputs whether they are equal to their reversed order or not.\n", - "* Example:\n", - "* Input >>> madam, tacocat, utrecht \n", - "* Output >>> True, True, False" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": "[True, True, False, True]" - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "list(map(lambda x: x==x[::-1],['madam','tacocat','utrecht','ada']))" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": "[True, True, False]" - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def reserved(x):\n", - " if x==x[::-1]:\n", - " return True\n", - " else:\n", - " return False\n", - "list(map(lambda x: reserved(x),['madam','tacocat','utrecht','ada']))" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3.8.5 64-bit ('base': conda)", - "name": "python385jvsc74a57bd0054e6073c53ecefb2cc966210e656e13c3a3c774a68778f6cdf25d7c37e20456" - }, - "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" - }, - "orig_nbformat": 2 - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file diff --git a/perfect_numbers.ipynb b/perfect_numbers.ipynb deleted file mode 100644 index dac132c..0000000 --- a/perfect_numbers.ipynb +++ /dev/null @@ -1,90 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* Perfect number: Perfect number is a positive integer that is equal to the sum of its proper divisors.\n", - "\n", - "* The smallest perfect number is 6, which is the sum of 1, 2, and 3.\n", - "\n", - "* Some other perfect numbers are 28(1+2+4+7+14=28), 496 and 8128.\n", - "\n", - "* Write a function that finds perfect numbers between 1 and 1000. Check perfect numbers between 1 and 1000 and find the sum of the perfect numbers using reduce and filter functions." - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [], - "source": [ - "def perfect_number(x):\n", - " summ=0\n", - " for i in range(1,x):\n", - " if x%i==0:\n", - " summ+=i\n", - " if summ==x:\n", - " return True" - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": "[6, 28, 496]" - }, - "execution_count": 35, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from functools import reduce\n", - "list(filter(lambda x: perfect_number(x),range(1,1000)))" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": "530" - }, - "execution_count": 36, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "reduce(lambda a,b:a+b,(list(filter(lambda x: perfect_number(x),range(1,1000)))))" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3.8.5 64-bit ('base': conda)", - "name": "python385jvsc74a57bd0054e6073c53ecefb2cc966210e656e13c3a3c774a68778f6cdf25d7c37e20456" - }, - "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" - }, - "orig_nbformat": 2 - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file diff --git a/reading_numbers.ipynb b/reading_numbers.ipynb deleted file mode 100644 index 46e00f1..0000000 --- a/reading_numbers.ipynb +++ /dev/null @@ -1,68 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "* Write a function that outputs the transcription of an input number with two digits.\n", - "\n", - "* Example:\n", - "\n", - "* 28---------------->Twenty Eight" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "99--------->Ninety Nine\n" - ] - } - ], - "source": [ - "reading1=['','One','Two','Three','Four','Five','Six','Seven','Eight','Nine']\n", - "reading2=['Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety']\n", - "reading3=['Ten','Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Nineteen']\n", - "def reading_numb():\n", - " x=input(\"A number only with two digits: \")\n", - " if x.isdigit()==False:\n", - " read= x\n", - " elif int(x)<10 or int(x)>99:\n", - " read= x\n", - " elif 20>int(x)>=10:\n", - " read='{}--------->{}'.format(x,reading3[int(x[1])])\n", - " \n", - " else:\n", - " read='{}--------->{} {}'.format(x,reading2[int(x[0])-2],reading1[int(x[1])])\n", - " return read\n", - "print(reading_numb())\n" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3.8.5 64-bit ('base': conda)", - "name": "python385jvsc74a57bd0054e6073c53ecefb2cc966210e656e13c3a3c774a68778f6cdf25d7c37e20456" - }, - "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" - }, - "orig_nbformat": 2 - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file diff --git a/unique_list.ipynb b/unique_list.ipynb deleted file mode 100644 index 83998df..0000000 --- a/unique_list.ipynb +++ /dev/null @@ -1,70 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n", - "* Write a function that filters all the unique(unrepeated) elements of a given list.\n", - "\n", - "* Example:\n", - "* Function call: unique_list([1,2,3,3,3,3,4,5,5])\n", - "* Output : [1, 2, 3, 4, 5]" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": "[1, 2, 3, 4, 5]" - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def unique_list(list):\n", - " new_list=[]\n", - " for i in list:\n", - " if i in new_list:\n", - " continue\n", - " else:\n", - " new_list.append(i)\n", - " return new_list\n", - "unique_list([1,2,3,3,3,3,4,5,5])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3.8.5 64-bit ('base': conda)", - "name": "python385jvsc74a57bd0054e6073c53ecefb2cc966210e656e13c3a3c774a68778f6cdf25d7c37e20456" - }, - "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" - }, - "orig_nbformat": 2 - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file From 3dd51b6e9c608161c83ddb01b1a661d02a18eefb Mon Sep 17 00:00:00 2001 From: mhmtnzly Date: Sun, 10 Oct 2021 01:04:14 +0200 Subject: [PATCH 12/12] v.0.2 --- hackerrank.py | 26 ++++++++++++++++++++++++++ q1.py | 19 +++++++++++++++++++ q2.py | 23 +++++++++++++++++++++++ q3.py | 19 +++++++++++++++++++ q4.py | 18 ++++++++++++++++++ q5.py | 14 ++++++++++++++ 6 files changed, 119 insertions(+) create mode 100644 hackerrank.py create mode 100644 q1.py create mode 100644 q2.py create mode 100644 q3.py create mode 100644 q4.py create mode 100644 q5.py diff --git a/hackerrank.py b/hackerrank.py new file mode 100644 index 0000000..66f8754 --- /dev/null +++ b/hackerrank.py @@ -0,0 +1,26 @@ +# ## Bonus Question 1 +# [HACKERRANK: FIND DIGITS](https://www.hackerrank.com/challenges/find-digits/problem) + +def findDigits(n): + n=str(n) + l=len(n) + summ=0 + for i in range(l): + if int(n[i])==0: + continue + elif int(n)%int(n[i])==0: + summ+=1 + return summ + +# ## Bonus Question 2 +# [HACKERRANK: CAPITALIZE](https://www.hackerrank.com/challenges/capitalize/problem) + +def solve(s): + s=s.split(' ') + for i in range(len(s)): + if s[i]=='': + continue + s[i]=s[i][0].capitalize()+s[i][1:] + s=' '.join([str(item) for item in s]) + return s +solve('chris alan') \ No newline at end of file diff --git a/q1.py b/q1.py new file mode 100644 index 0000000..2e04e1d --- /dev/null +++ b/q1.py @@ -0,0 +1,19 @@ +# ## 1-perfect_number.py +# Perfect number: Perfect number is a positive integer that is equal to the sum of its proper divisors. + +# The smallest perfect number is `6`, which is the sum of `1`, `2`, and `3`. + +# Some other perfect numbers are `28(1+2+4+7+14=28)`, `496` and `8128`. + +# Write a function that finds perfect numbers between `1` and `1000`. +# Check perfect numbers between `1` and `1000` and find the sum of the perfect numbers using reduce and filter functions.
+ +def perfect_number(x): + summ=0 + for i in range(1,x): + if x%i==0: + summ+=i + if summ==x: + return True +from functools import reduce +print(reduce(lambda a,b:a+b,(list(filter(lambda x: perfect_number(x),range(1,1000)))))) \ No newline at end of file diff --git a/q2.py b/q2.py new file mode 100644 index 0000000..03d5066 --- /dev/null +++ b/q2.py @@ -0,0 +1,23 @@ +# ## 2-reading_number.py +# Write a function that outputs the transcription of an input number with two digits. + +# Example: +# ``` +# 28---------------->Twenty Eight + +reading1=['','One','Two','Three','Four','Five','Six','Seven','Eight','Nine'] +reading2=['Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety'] +reading3=['Ten','Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Nineteen'] +def reading_numb(): + x=input("A number only with two digits: ") + if x.isdigit()==False: + read= x + elif int(x)<10 or int(x)>99: + read= x + elif 20>int(x)>=10: + read='{}--------->{}'.format(x,reading3[int(x[1])]) + + else: + read='{}--------->{} {}'.format(x,reading2[int(x[0])-2],reading1[int(x[1])]) + return read +print(reading_numb()) diff --git a/q3.py b/q3.py new file mode 100644 index 0000000..598b8a7 --- /dev/null +++ b/q3.py @@ -0,0 +1,19 @@ +# ## 3-alphabetical_order.py +# Write a function that takes an input of different words with hyphen (-) in between them and then:
+# * sorts the words in alphabetical order, +# * adds hyphen icon (-) between them, +# * gives the output of the sorted words. + +# Example: +# ``` +# Input >>> green-red-yellow-black-white +# Output >>> black-green-red-white-yellow +# ``` + +def alphabetical_order(): + words=input("Words with - : ") + words=words.split('-') + words.sort() + words='-'.join(words) + return words +print(alphabetical_order()) \ No newline at end of file diff --git a/q4.py b/q4.py new file mode 100644 index 0000000..a511492 --- /dev/null +++ b/q4.py @@ -0,0 +1,18 @@ +# ## 4-unique_list.py +# Write a function that filters all the unique(unrepeated) elements of a given list. + +# Example: +# ``` +# Function call: unique_list([1,2,3,3,3,3,4,5,5]) +# Output : [1, 2, 3, 4, 5] +# ``` + +def unique_list(list): + new_list=[] + for i in list: + if i in new_list: + continue + else: + new_list.append(i) + return new_list +unique_list([1,2,3,3,3,3,4,5,5]) \ No newline at end of file diff --git a/q5.py b/q5.py new file mode 100644 index 0000000..57fdd19 --- /dev/null +++ b/q5.py @@ -0,0 +1,14 @@ +# ## 5-equal_reverse.py +# Write a function that controls the given inputs whether they are equal to their reversed order or not. + +# Example: +# ``` +# Input >>> madam, tacocat, utrecht +# Output >>> True, True, False +# ``` +def reserved(x): + if x==x[::-1]: + return True + else: + return False +print(list(map(lambda x: reserved(x),['madam','tacocat','utrecht']))) \ No newline at end of file