Skip to content

Wilkenson break ice #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
254 changes: 250 additions & 4 deletions notebooks/Day_01.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,43 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"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,"
]
}
],
"source": [
"# solution by wilkensoncode\n",
"\n",
"def find_number_divisible(start:int, end:int) -> 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",
Expand Down Expand Up @@ -87,6 +121,84 @@
"- **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": 56,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter a number to get its factorial: 5\n"
]
},
{
"data": {
"text/plain": [
"120"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"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",
"factorial(number)\n",
"# w.h"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -110,6 +222,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,
Expand All @@ -131,6 +275,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,
Expand Down Expand Up @@ -186,6 +366,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,
Expand Down Expand Up @@ -217,6 +433,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,
Expand All @@ -227,7 +473,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -241,7 +487,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.9.13"
}
},
"nbformat": 4,
Expand Down
75 changes: 75 additions & 0 deletions wilkenson/day_1.py
Original file line number Diff line number Diff line change
@@ -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()))}