Skip to content

Commit 9ce55a4

Browse files
Forked Python
1 parent 3dd03b0 commit 9ce55a4

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed
+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## <center>Module-1 Test</center>"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 32,
13+
"metadata": {},
14+
"outputs": [
15+
{
16+
"name": "stdout",
17+
"output_type": "stream",
18+
"text": [
19+
"27\n"
20+
]
21+
},
22+
{
23+
"data": {
24+
"text/plain": [
25+
"9"
26+
]
27+
},
28+
"execution_count": 32,
29+
"metadata": {},
30+
"output_type": "execute_result"
31+
}
32+
],
33+
"source": [
34+
"'''\n",
35+
"You are given a two digit number n. Find the sum of its digits\n",
36+
"\n",
37+
"Input Format:\n",
38+
"The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains one line of input containing n.\n",
39+
"\n",
40+
"Output Format:\n",
41+
"For each testcase, in a new line, print the sum of digits of n.\n",
42+
"\n",
43+
"Your Task:\n",
44+
"This is a function problem. You do not need to take any input. Complete the function digitsSum and return the sum of digits of n.\n",
45+
"\n",
46+
"Constraints:\n",
47+
"1 <= T <= 100\n",
48+
"10 <= n <= 99\n",
49+
"\n",
50+
"Example:\n",
51+
"Input:\n",
52+
"1\n",
53+
"25\n",
54+
"Output:\n",
55+
"7\n",
56+
"'''\n",
57+
"n=int(input())\n",
58+
"sum_=0\n",
59+
"while n>0:\n",
60+
" r=n%10\n",
61+
" sum_+=r\n",
62+
" n//=10\n",
63+
"sum_"
64+
]
65+
},
66+
{
67+
"cell_type": "code",
68+
"execution_count": 31,
69+
"metadata": {},
70+
"outputs": [
71+
{
72+
"name": "stdout",
73+
"output_type": "stream",
74+
"text": [
75+
"2\n",
76+
"9\n",
77+
"8\n"
78+
]
79+
}
80+
],
81+
"source": [
82+
"'''\n",
83+
"You are given two numbers a and b. When a is raised to some power p, we get a number x. Now, you need to find what is the value of x that is closest to b.\n",
84+
"\n",
85+
"Input Format:\n",
86+
"The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains two lines of input. The first line contains a and second line contains b.\n",
87+
"\n",
88+
"Output Format:\n",
89+
"For each testcase, in a new line, print the closest power.\n",
90+
"\n",
91+
"Your Task:\n",
92+
"This is a function problem. You do not need to take any input. Complete the function nearestPower and return the answer.\n",
93+
"\n",
94+
"Constraints:\n",
95+
"1 <= T <= 100\n",
96+
"2 <= a <= 100\n",
97+
"a <= b <= 108\n",
98+
"\n",
99+
"Example:\n",
100+
"Input:\n",
101+
"1\n",
102+
"2\n",
103+
"4\n",
104+
"Output:\n",
105+
"4\n",
106+
"\n",
107+
"Explanation:\n",
108+
"Testcase1: 22=4 is closest to 4\n",
109+
"'''\n",
110+
"\n",
111+
"a=int(input())\n",
112+
"c=int(input())\n",
113+
"for i in range(1,c):\n",
114+
" if a**i==c:\n",
115+
" print(c)\n",
116+
" break\n",
117+
" if a**i>c:\n",
118+
" if (a**i-c)>=(c-a**(i-1)):\n",
119+
" print(a**(i-1))\n",
120+
" else:\n",
121+
" print(a**i)\n",
122+
" break"
123+
]
124+
},
125+
{
126+
"cell_type": "code",
127+
"execution_count": 34,
128+
"metadata": {},
129+
"outputs": [
130+
{
131+
"data": {
132+
"text/plain": [
133+
"2"
134+
]
135+
},
136+
"execution_count": 34,
137+
"metadata": {},
138+
"output_type": "execute_result"
139+
}
140+
],
141+
"source": [
142+
"'catinahatcat'.count('cat')"
143+
]
144+
},
145+
{
146+
"cell_type": "code",
147+
"execution_count": null,
148+
"metadata": {},
149+
"outputs": [],
150+
"source": []
151+
}
152+
],
153+
"metadata": {
154+
"kernelspec": {
155+
"display_name": "Python 3",
156+
"language": "python",
157+
"name": "python3"
158+
},
159+
"language_info": {
160+
"codemirror_mode": {
161+
"name": "ipython",
162+
"version": 3
163+
},
164+
"file_extension": ".py",
165+
"mimetype": "text/x-python",
166+
"name": "python",
167+
"nbconvert_exporter": "python",
168+
"pygments_lexer": "ipython3",
169+
"version": "3.7.5"
170+
}
171+
},
172+
"nbformat": 4,
173+
"nbformat_minor": 2
174+
}

0 commit comments

Comments
 (0)