Skip to content

Commit d3a383d

Browse files
committed
Day1 excercise questions
1 parent 22bb9b3 commit d3a383d

10 files changed

+880
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"Question 1\n",
8+
"Level 1\n",
9+
"\n",
10+
"Question:\n",
11+
"Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5,\n",
12+
"between 2000 and 3200 (both included).\n",
13+
"The numbers obtained should be printed in a comma-separated sequence on a single line."
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": 7,
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"list1 = [number for number in range(2000, 3200) if (number % 7 == 0 and number % 5 != 0)]\n",
23+
"\n",
24+
"for number in list1:\n",
25+
" print(str(number) + ',')\n",
26+
" "
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": 11,
32+
"metadata": {},
33+
"outputs": [],
34+
"source": [
35+
"str1 = \"\"\n",
36+
"for number in list1:\n",
37+
" str1 = str1 + ',' + str(number)"
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"execution_count": 14,
43+
"metadata": {},
44+
"outputs": [
45+
{
46+
"data": {
47+
"text/plain": [
48+
"'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'"
49+
]
50+
},
51+
"execution_count": 14,
52+
"metadata": {},
53+
"output_type": "execute_result"
54+
}
55+
],
56+
"source": [
57+
"str1[1:]"
58+
]
59+
},
60+
{
61+
"cell_type": "code",
62+
"execution_count": null,
63+
"metadata": {},
64+
"outputs": [],
65+
"source": []
66+
}
67+
],
68+
"metadata": {
69+
"kernelspec": {
70+
"display_name": "Python 3",
71+
"language": "python",
72+
"name": "python3"
73+
},
74+
"language_info": {
75+
"codemirror_mode": {
76+
"name": "ipython",
77+
"version": 3
78+
},
79+
"file_extension": ".py",
80+
"mimetype": "text/x-python",
81+
"name": "python",
82+
"nbconvert_exporter": "python",
83+
"pygments_lexer": "ipython3",
84+
"version": "3.6.4"
85+
}
86+
},
87+
"nbformat": 4,
88+
"nbformat_minor": 2
89+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"Question:\n",
8+
"Write a program which can compute the factorial of a given numbers.\n",
9+
"The results should be printed in a comma-separated sequence on a single line.\n",
10+
"Suppose the following input is supplied to the program:\n",
11+
"8\n",
12+
"Then, the output should be:\n",
13+
"40320\n",
14+
"\n",
15+
"Hints:\n",
16+
"In case of input data being supplied to the question, it should be assumed to be a console input.\n"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": 2,
22+
"metadata": {},
23+
"outputs": [],
24+
"source": [
25+
"def factorial(x):\n",
26+
" if x == 0:\n",
27+
" return 1\n",
28+
" else:\n",
29+
" return x * factorial(x - 1)"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": 8,
35+
"metadata": {},
36+
"outputs": [
37+
{
38+
"name": "stdout",
39+
"output_type": "stream",
40+
"text": [
41+
"Please enter the number for which you wish to get the factorial8\n",
42+
"40320\n"
43+
]
44+
}
45+
],
46+
"source": [
47+
"number = int(input(\"Please enter the number for which you wish to get the factorial\"))\n",
48+
"factorial1 = factorial(number)\n",
49+
"print(factorial1)"
50+
]
51+
}
52+
],
53+
"metadata": {
54+
"kernelspec": {
55+
"display_name": "Python 3",
56+
"language": "python",
57+
"name": "python3"
58+
},
59+
"language_info": {
60+
"codemirror_mode": {
61+
"name": "ipython",
62+
"version": 3
63+
},
64+
"file_extension": ".py",
65+
"mimetype": "text/x-python",
66+
"name": "python",
67+
"nbconvert_exporter": "python",
68+
"pygments_lexer": "ipython3",
69+
"version": "3.6.4"
70+
}
71+
},
72+
"nbformat": 4,
73+
"nbformat_minor": 2
74+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"Question:\n",
8+
"With a given integral number n, write a program to generate a dictionary that contains (i, i*i) such that is an integral number between 1 and n (both included). and then the program should print the dictionary.\n",
9+
"Suppose the following input is supplied to the program:\n",
10+
"8\n",
11+
"Then, the output should be:\n",
12+
"{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}\n",
13+
"\n",
14+
"Hints:\n",
15+
"In case of input data being supplied to the question, it should be assumed to be a console input.\n",
16+
"Consider use dict()"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": 8,
22+
"metadata": {},
23+
"outputs": [
24+
{
25+
"name": "stdout",
26+
"output_type": "stream",
27+
"text": [
28+
"Please provide the number8\n"
29+
]
30+
}
31+
],
32+
"source": [
33+
"my_dict = {}\n",
34+
"number = int(input(\"Please provide the number\"))"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": 9,
40+
"metadata": {},
41+
"outputs": [],
42+
"source": [
43+
"my_dict = {}\n",
44+
"for number in range(1, number + 1):\n",
45+
" my_dict[number] = number ** 2"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": 10,
51+
"metadata": {},
52+
"outputs": [
53+
{
54+
"name": "stdout",
55+
"output_type": "stream",
56+
"text": [
57+
"{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}\n"
58+
]
59+
}
60+
],
61+
"source": [
62+
"print(my_dict)"
63+
]
64+
}
65+
],
66+
"metadata": {
67+
"kernelspec": {
68+
"display_name": "Python 3",
69+
"language": "python",
70+
"name": "python3"
71+
},
72+
"language_info": {
73+
"codemirror_mode": {
74+
"name": "ipython",
75+
"version": 3
76+
},
77+
"file_extension": ".py",
78+
"mimetype": "text/x-python",
79+
"name": "python",
80+
"nbconvert_exporter": "python",
81+
"pygments_lexer": "ipython3",
82+
"version": "3.6.4"
83+
}
84+
},
85+
"nbformat": 4,
86+
"nbformat_minor": 2
87+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"Question:4\n",
8+
"Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number.\n",
9+
"Suppose the following input is supplied to the program:\n",
10+
"34,67,55,33,12,98\n",
11+
"Then, the output should be:\n",
12+
"\n",
13+
"['34', '67', '55', '33', '12', '98']\n",
14+
"\n",
15+
"('34', '67', '55', '33', '12', '98')\n",
16+
"\n",
17+
"Hints:\n",
18+
"In case of input data being supplied to the question, it should be assumed to be a console input.\n",
19+
"tuple() method can convert list to tuple"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 1,
25+
"metadata": {},
26+
"outputs": [
27+
{
28+
"name": "stdout",
29+
"output_type": "stream",
30+
"text": [
31+
"Please provide the num seperated by ',': 34,67,55,33,12,98\n"
32+
]
33+
}
34+
],
35+
"source": [
36+
"str1 = input(\"Please provide the num seperated by ',': \")"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": 2,
42+
"metadata": {},
43+
"outputs": [
44+
{
45+
"name": "stdout",
46+
"output_type": "stream",
47+
"text": [
48+
"34,67,55,33,12,98\n",
49+
"['34', '67', '55', '33', '12', '98']\n"
50+
]
51+
}
52+
],
53+
"source": [
54+
"print(str1)\n",
55+
"lst1 = str1.split(',')\n",
56+
"print(lst1)\n"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": 3,
62+
"metadata": {},
63+
"outputs": [
64+
{
65+
"name": "stdout",
66+
"output_type": "stream",
67+
"text": [
68+
"('34', '67', '55', '33', '12', '98')\n"
69+
]
70+
}
71+
],
72+
"source": [
73+
"lst2 = tuple(lst1)\n",
74+
"print(lst2)"
75+
]
76+
}
77+
],
78+
"metadata": {
79+
"kernelspec": {
80+
"display_name": "Python 3",
81+
"language": "python",
82+
"name": "python3"
83+
},
84+
"language_info": {
85+
"codemirror_mode": {
86+
"name": "ipython",
87+
"version": 3
88+
},
89+
"file_extension": ".py",
90+
"mimetype": "text/x-python",
91+
"name": "python",
92+
"nbconvert_exporter": "python",
93+
"pygments_lexer": "ipython3",
94+
"version": "3.6.4"
95+
}
96+
},
97+
"nbformat": 4,
98+
"nbformat_minor": 2
99+
}

0 commit comments

Comments
 (0)