Skip to content

Commit 7b1f66e

Browse files
committed
Premid
1 parent 4a2fa0c commit 7b1f66e

File tree

4 files changed

+2235
-0
lines changed

4 files changed

+2235
-0
lines changed

Pre mid.ipynb

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import pandas as pd"
10+
]
11+
},
12+
{
13+
"cell_type": "markdown",
14+
"metadata": {},
15+
"source": [
16+
"ข้อ 1\n",
17+
"สร้าง function ชื่อ createDict ซึ่งทำหน้าที่:\n",
18+
"- function รับ input เป็น list 2 ตัวที่มีขนาดเท่ากัน และ ค่า True/False\n",
19+
"- ถ้า True จะสร้าง dict ที่มี key(index) เป็นค่าจาก list ตัวที่ 1 และ value จาก list ตัวที่ 2\n",
20+
" if TF == True: same as if TF:\n",
21+
"- ถ้า False จะสร้าง dict ที่มี key เป็นค่าจาก list ตัวที่ 2 และ value จาก list ตัวที่ 1\n",
22+
"- output ของ function คือ dict ที่สร้างขึ้น\n",
23+
"\n",
24+
"เช่น\n",
25+
"\n",
26+
"output1 = createDict( [ 'apple' , 'banana' ] , [ 1 , 2 ] , True )\n",
27+
"\n",
28+
"จะได้ output1 เป็น { 'apple' : 1 , 'banana' : 2 }\n",
29+
"\n",
30+
"output2 = createDict( [ 'apple' , 'banana' ] , [ 1 , 2 ] , False )\n",
31+
"\n",
32+
"จะได้ output2 เป็น { 1 : 'apple' , 2 : 'banana' }"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": 8,
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"def CreateDict(listtext,listnum,TF):\n",
42+
" if TF == True:\n",
43+
" em_dict = {}\n",
44+
" for index in range(len(listtext)):\n",
45+
" em_dict[listtext[index]] = listnum[index]\n",
46+
" else:\n",
47+
" em_dict = {}\n",
48+
" for index in range(len(listtext)):\n",
49+
" em_dict[listnum[index]] = listtext[index]\n",
50+
" return em_dict"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": 10,
56+
"metadata": {},
57+
"outputs": [
58+
{
59+
"data": {
60+
"text/plain": [
61+
"{1: 'apple', 2: 'banana'}"
62+
]
63+
},
64+
"execution_count": 10,
65+
"metadata": {},
66+
"output_type": "execute_result"
67+
}
68+
],
69+
"source": [
70+
"CreateDict(['apple','banana'],[1,2],True)"
71+
]
72+
},
73+
{
74+
"cell_type": "code",
75+
"execution_count": 11,
76+
"metadata": {},
77+
"outputs": [
78+
{
79+
"data": {
80+
"text/plain": [
81+
"{1: 'apple', 2: 'banana'}"
82+
]
83+
},
84+
"execution_count": 11,
85+
"metadata": {},
86+
"output_type": "execute_result"
87+
}
88+
],
89+
"source": [
90+
"CreateDict(['apple','banana'],[1,2],False)"
91+
]
92+
},
93+
{
94+
"cell_type": "markdown",
95+
"metadata": {},
96+
"source": [
97+
"ข้อ 2 สร้าง function ชื่อ genPassword สำหรับสร้าง list ของ password:\n",
98+
"\n",
99+
"- function รับค่า input เป็น ความยาวของ password และ จำนวนของ password\n",
100+
"- output เป็น list ของ password ที่สร้างขึ้น\n",
101+
"- เงื่อนไขการสร้าง password คือ ต้องเป็นตัวอักษรภาษาอังกฤษตัวเล็กสลับตัวเลข โดยเป็นค่าที่ถูก random มา \n",
102+
"\n",
103+
"ตัวอย่างเช่น\n",
104+
"\n",
105+
"output = genPassword( 8 , 3 )\n",
106+
"\n",
107+
"จะได้ผลลัพธ์ เช่น [ 'n3k2p8z6' , 'g5h4f2h2' , 'b9c3t4h9' ]"
108+
]
109+
},
110+
{
111+
"cell_type": "code",
112+
"execution_count": null,
113+
"metadata": {},
114+
"outputs": [],
115+
"source": [
116+
"def genPassword(lenp,nump)\n"
117+
]
118+
}
119+
],
120+
"metadata": {
121+
"kernelspec": {
122+
"display_name": "Python 3",
123+
"language": "python",
124+
"name": "python3"
125+
},
126+
"language_info": {
127+
"codemirror_mode": {
128+
"name": "ipython",
129+
"version": 3
130+
},
131+
"file_extension": ".py",
132+
"mimetype": "text/x-python",
133+
"name": "python",
134+
"nbconvert_exporter": "python",
135+
"pygments_lexer": "ipython3",
136+
"version": "3.7.4"
137+
}
138+
},
139+
"nbformat": 4,
140+
"nbformat_minor": 2
141+
}

0 commit comments

Comments
 (0)