Skip to content

Commit e4d0c55

Browse files
committed
Added extra notebooks
1 parent 5a31fdf commit e4d0c55

14 files changed

+1295
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"Question:\n",
8+
" Write a method which can calculate square value of number\n",
9+
"\n",
10+
"Hints:\n",
11+
" Using the ** operator\n"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 1,
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"def square_number(x):\n",
21+
" return x ** 2"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": 2,
27+
"metadata": {},
28+
"outputs": [
29+
{
30+
"name": "stdout",
31+
"output_type": "stream",
32+
"text": [
33+
"please provide the number you wish to get the square of: 25\n"
34+
]
35+
}
36+
],
37+
"source": [
38+
"number = int(input(\"please provide the number you wish to get the square of: \"))"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": 3,
44+
"metadata": {},
45+
"outputs": [
46+
{
47+
"name": "stdout",
48+
"output_type": "stream",
49+
"text": [
50+
"625\n"
51+
]
52+
}
53+
],
54+
"source": [
55+
"answer = square_number(number)\n",
56+
"print(answer)"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"metadata": {},
63+
"outputs": [],
64+
"source": []
65+
}
66+
],
67+
"metadata": {
68+
"kernelspec": {
69+
"display_name": "Python 3",
70+
"language": "python",
71+
"name": "python3"
72+
},
73+
"language_info": {
74+
"codemirror_mode": {
75+
"name": "ipython",
76+
"version": 3
77+
},
78+
"file_extension": ".py",
79+
"mimetype": "text/x-python",
80+
"name": "python",
81+
"nbconvert_exporter": "python",
82+
"pygments_lexer": "ipython3",
83+
"version": "3.6.4"
84+
}
85+
},
86+
"nbformat": 4,
87+
"nbformat_minor": 2
88+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"Question:\n",
8+
" Python has many built-in functions, and if you do not know how to use it, you can read document online or find some books. But Python has a built-in document function for every built-in functions.\n",
9+
" Please write a program to print some Python built-in functions documents, such as abs(), int(), raw_input()\n",
10+
" And add document for your own function\n",
11+
" \n",
12+
"Hints:\n",
13+
" The built-in document method is __doc__\n"
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": 2,
19+
"metadata": {},
20+
"outputs": [
21+
{
22+
"name": "stdout",
23+
"output_type": "stream",
24+
"text": [
25+
"Return the absolute value of the argument.\n"
26+
]
27+
}
28+
],
29+
"source": [
30+
"print(abs.__doc__)"
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": 3,
36+
"metadata": {},
37+
"outputs": [
38+
{
39+
"name": "stdout",
40+
"output_type": "stream",
41+
"text": [
42+
"int(x=0) -> integer\n",
43+
"int(x, base=10) -> integer\n",
44+
"\n",
45+
"Convert a number or string to an integer, or return 0 if no arguments\n",
46+
"are given. If x is a number, return x.__int__(). For floating point\n",
47+
"numbers, this truncates towards zero.\n",
48+
"\n",
49+
"If x is not a number or if base is given, then x must be a string,\n",
50+
"bytes, or bytearray instance representing an integer literal in the\n",
51+
"given base. The literal can be preceded by '+' or '-' and be surrounded\n",
52+
"by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.\n",
53+
"Base 0 means to interpret the base from the string as an integer literal.\n",
54+
">>> int('0b100', base=0)\n",
55+
"4\n"
56+
]
57+
}
58+
],
59+
"source": [
60+
"print(int.__doc__)"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": 7,
66+
"metadata": {},
67+
"outputs": [
68+
{
69+
"ename": "NameError",
70+
"evalue": "name 'raw_input' is not defined",
71+
"output_type": "error",
72+
"traceback": [
73+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
74+
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
75+
"\u001b[0;32m<ipython-input-7-e52e53143727>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mraw_input\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__doc__\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
76+
"\u001b[0;31mNameError\u001b[0m: name 'raw_input' is not defined"
77+
]
78+
}
79+
],
80+
"source": [
81+
"print(raw_input.__doc__)"
82+
]
83+
},
84+
{
85+
"cell_type": "code",
86+
"execution_count": null,
87+
"metadata": {},
88+
"outputs": [],
89+
"source": []
90+
}
91+
],
92+
"metadata": {
93+
"kernelspec": {
94+
"display_name": "Python 3",
95+
"language": "python",
96+
"name": "python3"
97+
},
98+
"language_info": {
99+
"codemirror_mode": {
100+
"name": "ipython",
101+
"version": 3
102+
},
103+
"file_extension": ".py",
104+
"mimetype": "text/x-python",
105+
"name": "python",
106+
"nbconvert_exporter": "python",
107+
"pygments_lexer": "ipython3",
108+
"version": "3.6.4"
109+
}
110+
},
111+
"nbformat": 4,
112+
"nbformat_minor": 2
113+
}
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+
"Define a function which can compute the sum of two numbers.\n",
8+
"\n",
9+
"Hints:\n",
10+
"Define a function with two numbers as arguments. You can compute the sum in the function and return the value."
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 1,
16+
"metadata": {},
17+
"outputs": [],
18+
"source": [
19+
"def sum(x, y):\n",
20+
" return x + y"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": 2,
26+
"metadata": {},
27+
"outputs": [
28+
{
29+
"name": "stdout",
30+
"output_type": "stream",
31+
"text": [
32+
"Please provide the first number : 5\n",
33+
"Please provide the first number : 8\n",
34+
"13\n"
35+
]
36+
}
37+
],
38+
"source": [
39+
"x = int(input(\"Please provide the first number : \"))\n",
40+
"y = int(input(\"Please provide the first number : \"))\n",
41+
"sum1 = sum(x, y)\n",
42+
"print(sum1)"
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": null,
48+
"metadata": {},
49+
"outputs": [],
50+
"source": []
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"Question:\n",
8+
"Define a function that can convert a integer into a string and print it in console.\n",
9+
"\n",
10+
"Hints:\n",
11+
"\n",
12+
"Use str() to convert a number to string."
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": 1,
18+
"metadata": {},
19+
"outputs": [],
20+
"source": [
21+
"def int_to_str(x):\n",
22+
" return str(x)"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": 2,
28+
"metadata": {},
29+
"outputs": [
30+
{
31+
"name": "stdout",
32+
"output_type": "stream",
33+
"text": [
34+
"Please provide a number that needs to be converted into string: 546\n"
35+
]
36+
}
37+
],
38+
"source": [
39+
"x = int(input(\"Please provide a number that needs to be converted into string: \"))"
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": 3,
45+
"metadata": {},
46+
"outputs": [
47+
{
48+
"name": "stdout",
49+
"output_type": "stream",
50+
"text": [
51+
"546\n"
52+
]
53+
}
54+
],
55+
"source": [
56+
"str1 = int_to_str(x)\n",
57+
"print(str1)"
58+
]
59+
},
60+
{
61+
"cell_type": "code",
62+
"execution_count": 4,
63+
"metadata": {},
64+
"outputs": [
65+
{
66+
"data": {
67+
"text/plain": [
68+
"str"
69+
]
70+
},
71+
"execution_count": 4,
72+
"metadata": {},
73+
"output_type": "execute_result"
74+
}
75+
],
76+
"source": [
77+
"type(str1)"
78+
]
79+
},
80+
{
81+
"cell_type": "code",
82+
"execution_count": null,
83+
"metadata": {},
84+
"outputs": [],
85+
"source": []
86+
}
87+
],
88+
"metadata": {
89+
"kernelspec": {
90+
"display_name": "Python 3",
91+
"language": "python",
92+
"name": "python3"
93+
},
94+
"language_info": {
95+
"codemirror_mode": {
96+
"name": "ipython",
97+
"version": 3
98+
},
99+
"file_extension": ".py",
100+
"mimetype": "text/x-python",
101+
"name": "python",
102+
"nbconvert_exporter": "python",
103+
"pygments_lexer": "ipython3",
104+
"version": "3.6.4"
105+
}
106+
},
107+
"nbformat": 4,
108+
"nbformat_minor": 2
109+
}

0 commit comments

Comments
 (0)