

การเขียนโปรแกรมไพทอน
Presentation
•
Computers
•
7th - 12th Grade
•
Practice Problem
•
Hard
ครูวีรวัฒน์ ศักดิ์เพชรพลอย
Used 136+ times
FREE Resource
11 Slides • 10 Questions
1
Python List & Dict

2
List (ลิสต์)
ใช้เก็บข้อมูลจำนวนมากได้
ใช้ตัวเลขตำแหน่ง (index) ในการระบุตำแหน่ง
ตำแหน่งแรกของลิสต์คือ 0
สามารถเก็บได้ทั้ง ตัวเลข ตัวอักษร ค่าความจริง ลิสต์ และ ดิกต์
ใช้กฏการกำหนดชื่อเหมือนตัวแปรอื่น
ใช้เครื่องหมาย [ ] ในการสร้างลิสต์
3
ตัวอย่างการใช้ List
Code >>
name = ['Penny','Ellie','Koby','Olive','Ran','Andy']
print('คนที่ 1 คือ ',name[0])
print('คนที่ 3 คือ ',name[2])
print('คนที่ 5 คือ ',name[4])
Output >>
คนที่ 1 คือ Penny
คนที่ 3 คือ Koby
คนที่ 5 คือ Ran
4
Multiple Choice
name = ['Penny','Ellie','Koby','Olive','Ran','Andy']
คำถาม ถ้าต้องการให้โปรแกรมแสดงผลว่า Ran จะต้องใช้คำสั่งในข้อใด
print(5)
print(4)
print(name[5])
print(name[4])
5
Dict (ดิกต์)
ใช้เก็บข้อมูลจำนวนมากได้
ใช้ key ในการระบุตำแหน่ง
สามารถแทน key เป็น ตัวเลข ตัวอักษร ค่าความจริง ได้
สามารถเก็บได้ทั้ง ตัวเลข ตัวอักษร ค่าความจริง ลิสต์ และ ดิกต์
ใช้กฏการกำหนดชื่อเหมือนตัวแปรอื่น
ใช้เครื่องหมาย { } ในการสร้างดิกต์
6
ตัวอย่างการใช้ Dict
Code >>
student1 = {'id' : 9 , 'name' : 'Misty Lake'}
student2 = {'id' : 8 , 'name' : 'Scarlet Devil'}
print('รหัสนักเรียน', student1['id'], ' ชื่อ ', student9['name'])
print('รหัสนักเรียน', student2['id'], ' ชื่อ ', student8['name'])
Output >>
รหัสนักเรียน 9 ชื่อ Misty Lake
รหัสนักเรียน 8 ชื่อ Scarlet Devil
7
Multiple Choice
ถ้านักเรียนต้องการสร้าง Dict นักเรียนควรใช้สัญลักษณ์ใด
[ ]
( )
{ }
" "
8
Multiple Choice
ข้อใดต่อไปนี้ไม่สามารถใช้เป็น key ของ dict ได้
"Bob"
20
[20]
False
9
ตัวอย่างการใช้ List & Dict
Code >>
student = []
student.append( {'id' : 9 , 'name' : 'Misty Lake'} )
student.append( {'id' : 8 , 'name' : 'Scarlet Devil'} )
print('รหัสนักเรียน', student[0]['id'], ' ชื่อ ', student[0]['name'])
print('รหัสนักเรียน', student[1]['id'], ' ชื่อ ', student[1]['name'])
Output >>
รหัสนักเรียน 9 ชื่อ Misty Lake
รหัสนักเรียน 8 ชื่อ Scarlet Devil
10
Multiple Choice
snack = [{'id':1,'name':Lays},{'id':2,'name':Kitkat},{'id':3,'name':Pocky}]
ในลิสต์สินค้ามีขนมอยู่ 3 ชนิด ถ้าต้องการสั่ง Kitkat จะต้องสั่งสินค้าลำดับที่เท่าไร
0
1
2
11
Multiple Choice
snack = [{'id':1,'name':Lays},{'id':2,'name':Kitkat},{'id':3,'name':Pocky}]
จากข้อที่แล้วถ้าอยากได้ ชื่อสินค้า จะต้องเขียนโค๊ดตามข้อใด
snake[1]{'name'}
snack[1]['name']
snack[2]{'name'}
snack[2]{'name'}
12
การใช้ append & sort
Code >>
number = []
number.append(90)
number.append(65)
number.append(70)
number.sort()
print(number)
Output >>
[65,70,90]
13
การกำหนดค่าหลายตัวแปรโดยใช้ List
Code >>
number = []
number.append(90)
number.append(65)
number.append(70)
x,y,z = number
print('x = ',x,' y = ',y,' z = ',z)
Output >>
x = 90 y = 65 z = 70
14
การใช้ pop
Code >>
number = [60,70,90,100]
number.pop(2)
x,y,z = number
print('x = ',x,' y = ',y,' z = ',z)
Output >>
x = 65 y = 70 z = 100
15
การใช้ pop
Code >>
number = [60,70,90,100]
number.pop(2)
x,y,z = number
print(number.pop(2))
print(number)
Output >>
100
[60, 70]
16
การใช้ insert
Code >>
number = [60,90]
number.insert(1,70)
x,y,z = number
print(number)
Output >>
[60, 70 ,90]
17
Multiple Choice
2 + 3 + 5 x 0 + 5 x 2 + 10 x 0 = ?
5
10
15
0
18
Multiple Select
คำสั่งใดเป็นคำสั่งสำหรับเพิ่มค่าใน list (ตอบได้หลายตัวเลือก)
append
pop
insert
sort
19
Fill in the Blanks
choice = {False:"ผิด",True:"ถูกต้อง"}
print(choice[_])
ให้นักเรียนพิมพ์คำตอบที่ถูกต้องที่ควรเติมลงในช่องว่าง _
Type answer...
20
Multiple Select
li = []
li.append(1,"Hello")
print("Hi")
print(li[1])
จากโค๊ดจะเกิด error บรรทัดใดบ้าง (เลือกตอบได้หลายบรรทัด)
1
2
3
4
ไม่มี Error
21
Multiple Choice
วันนี้เป็นวัน
ปีใหม่
สงกรานต์
พุธ
พุทธ
Python List & Dict

Show answer
Auto Play
Slide 1 / 21
SLIDE
Similar Resources on Wayground
16 questions
Macromolecules Practice
Presentation
•
8th - 12th Grade
18 questions
Prokaryotic and Eukaryotic Cells
Presentation
•
6th Grade - University
17 questions
Networks
Presentation
•
8th - 12th Grade
17 questions
Social Media
Presentation
•
9th - 12th Grade
20 questions
Essay Structure Review
Presentation
•
7th - 12th Grade
17 questions
UNIT11:ITIDAT0171A Operate a Spreadsheet Application (basic)
Presentation
•
7th - 11th Grade
13 questions
Earth's Biogeochemical Cycles
Presentation
•
8th - 12th Grade
18 questions
Parabola Basics
Presentation
•
8th - 11th Grade
Popular Resources on Wayground
10 questions
How much do you know about our Portrait of an Eagle?
Quiz
•
10th Grade
10 questions
Fast Food Slogans
Quiz
•
6th - 8th Grade
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
12 questions
Map Skills
Quiz
•
3rd Grade
22 questions
Continents and Oceans
Quiz
•
5th Grade
Discover more resources for Computers
10 questions
Exploring Digital Citizenship Essentials
Interactive video
•
6th - 10th Grade
20 questions
Copyright and Fair Use
Quiz
•
6th - 8th Grade
20 questions
[AP CSP] Python Coding: Functions, Parameters, Return
Presentation
•
9th - 12th Grade
15 questions
Internet Safety
Quiz
•
7th Grade
40 questions
Introduction to Microsoft Word
Quiz
•
8th - 12th Grade
20 questions
APCS Unit 1A
Quiz
•
9th - 12th Grade
24 questions
Binary
Quiz
•
9th - 12th Grade