From a78519226f8367f745f45eae6cdf3065fccc717e Mon Sep 17 00:00:00 2001 From: wilkenson Date: Wed, 12 Apr 2023 15:12:17 -0400 Subject: [PATCH 1/3] wilkensoncode: day 1 solution --- .DS_Store | Bin 0 -> 6148 bytes notebooks/Day_01.ipynb | 245 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 241 insertions(+), 4 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d0eb92294f9e7701608acf67c13493e992dfea4e GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8O(;SR3OxqA7L2tB#Y>3w1&ruHr6we3Xv|8JnnNk%tS{t~_&m<+ zZp6|GoCM*xj zm27hSMFw!~OqRi_6)a|7)-QhwQxQV+EqqFoyl|X%-e|VAw%bPA=oq*DgDCwXC}z1A zOs}zbAw(M1b`V}BaXGejPeoP)Nfu9KK@!D~a&whrktjVe%c5M?`YK?UhB>yn^ZCFT z_Uu7_u;|(IVc!A!=y int:\n", + " for num in range(start, end + 1):\n", + " if num % 7 == 0 and not num % 5 == 0:\n", + " print(num, end=\",\")\n", + " print()\n", + " \n", + "find_number_divisible(2000, 3200)\n", + "#w.h" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2002,2009,2016,2023,2037,2044,2051,2058,2072,2079,2086,2093,2107,2114,2121,2128,2142,2149,2156,2163,2177,2184,2191,2198,2212,2219,2226,2233,2247,2254,2261,2268,2282,2289,2296,2303,2317,2324,2331,2338,2352,2359,2366,2373,2387,2394,2401,2408,2422,2429,2436,2443,2457,2464,2471,2478,2492,2499,2506,2513,2527,2534,2541,2548,2562,2569,2576,2583,2597,2604,2611,2618,2632,2639,2646,2653,2667,2674,2681,2688,2702,2709,2716,2723,2737,2744,2751,2758,2772,2779,2786,2793,2807,2814,2821,2828,2842,2849,2856,2863,2877,2884,2891,2898,2912,2919,2926,2933,2947,2954,2961,2968,2982,2989,2996,3003,3017,3024,3031,3038,3052,3059,3066,3073,3087,3094,3101,3108,3122,3129,3136,3143,3157,3164,3171,3178,3192,3199,\b\n" + ] + } + ], "source": [ "for i in range(2000, 3201):\n", " if i % 7 == 0 and i % 5 != 0:\n", @@ -87,6 +121,75 @@ "- **Using While Loop**" ] }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter a number to get its factorial: 5\n" + ] + }, + { + "data": { + "text/plain": [ + "120" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# using while loop\n", + "# solution by wilkensoncode\n", + "\n", + "number = (int)(input(\"Enter a number to get its factorial: \"))\n", + "factorial = 1\n", + "incre = 1\n", + "while incre <= number:\n", + " factorial = factorial * incre\n", + " incre += 1\n", + "\n", + "factorial\n", + "# w.h" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter a number to get its factorial: 8\n", + "40320\n" + ] + } + ], + "source": [ + "# using recursion\n", + "# solution by wilkensoncode\n", + "\n", + "def factorial(num:int):\n", + " if num == 1:\n", + " return num\n", + " if num <= 0:\n", + " return\n", + " return num * factorial(num - 1)\n", + " \n", + " \n", + "number = (int)(input(\"Enter a number to get its factorial: \"))\n", + "compute_factorial(number)\n", + "# w.h" + ] + }, { "cell_type": "code", "execution_count": null, @@ -110,6 +213,38 @@ "- **Using For Loop**" ] }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter a number to get factorial: 5\n" + ] + }, + { + "data": { + "text/plain": [ + "120" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# solution by wilkensoncode\n", + "fact = 1\n", + "for i in range(1, 1 + int(input('Enter a number to get factorial: '))):\n", + " fact = fact * i\n", + "fact\n", + "# w.h" + ] + }, { "cell_type": "code", "execution_count": null, @@ -131,6 +266,42 @@ "- **Using Lambda Function**" ] }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "enter number get factorial: 5\n" + ] + }, + { + "data": { + "text/plain": [ + "120" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# solution by wilkensoncode\n", + "\n", + " \n", + "factorial = lambda x : 1 if x == 0 else x * factorial(x -1)\n", + "factorial(5)\n", + "\n", + "m = (int) (input(\"enter number get factorial: \"))\n", + "factorial(m)\n", + "\n", + "# w.h" + ] + }, { "cell_type": "code", "execution_count": null, @@ -186,6 +357,42 @@ "- **Using For loop**" ] }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n" + ] + }, + { + "data": { + "text/plain": [ + "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# solution by wilkensoncode\n", + "n = (int)(input())\n", + "\n", + "book = {}\n", + "\n", + "for i in range(1 , n + 1):\n", + " book[i] = i*i\n", + "\n", + "book\n", + "# w.h" + ] + }, { "cell_type": "code", "execution_count": null, @@ -217,6 +424,36 @@ "print(ans)" ] }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n" + ] + }, + { + "data": { + "text/plain": [ + "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# olution by wilkensoncode\n", + "{x : x * x for x in range(1, 1 + int(input()))}\n", + "\n", + "# w.h" + ] + }, { "cell_type": "code", "execution_count": null, @@ -227,7 +464,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -241,7 +478,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.9.13" } }, "nbformat": 4, From d367f35eb396bcd349d9ca1abd835de321a962f4 Mon Sep 17 00:00:00 2001 From: wilkenson Date: Thu, 13 Apr 2023 10:19:26 -0400 Subject: [PATCH 2/3] day_1 solutions --- notebooks/Day_01.ipynb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/notebooks/Day_01.ipynb b/notebooks/Day_01.ipynb index 6969ef3..0e97055 100644 --- a/notebooks/Day_01.ipynb +++ b/notebooks/Day_01.ipynb @@ -161,16 +161,25 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 56, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Enter a number to get its factorial: 8\n", - "40320\n" + "Enter a number to get its factorial: 5\n" ] + }, + { + "data": { + "text/plain": [ + "120" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -186,7 +195,7 @@ " \n", " \n", "number = (int)(input(\"Enter a number to get its factorial: \"))\n", - "compute_factorial(number)\n", + "factorial(number)\n", "# w.h" ] }, From 47ee39dc912aa0a9dc5543e3eb70676d6bab8fbc Mon Sep 17 00:00:00 2001 From: wilkenson Date: Fri, 14 Apr 2023 11:37:16 -0400 Subject: [PATCH 3/3] day 1 solutions --- wilkenson/day_1.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 wilkenson/day_1.py diff --git a/wilkenson/day_1.py b/wilkenson/day_1.py new file mode 100644 index 0000000..0b1fd38 --- /dev/null +++ b/wilkenson/day_1.py @@ -0,0 +1,75 @@ +# solution by wilkensoncode +# Q1 +def find_number_divisible(start: int, end: int) -> int: + for num in range(start, end + 1): + if num % 7 == 0 and not num % 5 == 0: + print(num, end=",") + print() + + +find_number_divisible(2000, 3200) + +# using while loop +# Q2 +number = (int)(input("Enter a number to get its factorial: ")) + + +def factorial(): + factorial = 1 + incre = 1 + while incre <= number: + factorial = factorial * incre + incre += 1 + + +factorial(number) + +# using recursion + + +def r_factorial(num: int): + if num == 1: + return num + if num <= 0: + return + return num * factorial(num - 1) + + +number = (int)(input("Enter a number to get its factorial: ")) +r_factorial(number) + +# using for loop + + +def for_factorial(): + fact = 1 + for i in range(1, 1 + int(input('Enter a number to get factorial: '))): + fact = fact * i + fact + + +for_factorial() + + +# lambda soluion +def factorial(x): return 1 if x == 0 else x * factorial(x - 1) + + +factorial(5) + +m = (int)(input("enter number get factorial: ")) +factorial(m) + +# Q3 solution +n = (int)(input()) + +book = {} + +for i in range(1, n + 1): + book[i] = i*i + +book + + +# dict comprehension +{x: x * x for x in range(1, 1 + int(input()))}