
Bài học không có tiêu đề
Presentation
•
Computers
•
Vocational training
•
Practice Problem
•
Hard
Quang Pham
Used 3+ times
FREE Resource
31 Slides • 0 Questions
1
Đây là một sản phẩm trí tuệ có bản quyền thuộc về STEAM for Vietnam. Các bên chỉ được sử dụng với mục đích học
tập, nghiên cứu, và không được quyền sử dụng sản phẩm này nhằm mục đích thu lợi nhuận dù trực tiếp hay gián tiếp.
RFC2024
Pre-course Python
1
Introduction to robotics
2
RFC2024
2
Pre-course Python
Mở Webots
Chiến Python
3
#Hello world
print("Robot của anh tài")
Bắt đầu với Hello World
# Đã chiến xong -–>
4
CS 202
BIẾN (Variable)
4
Pre-course Python
print()
XUẤT MÀN HÌNH
x=2
BIẾN
Giá trị
Tên biến
5
5
RFC2024
5
STRING
"VEXCapybara"
'1562'
String là một tập hợp
các kí tự, chữ
"p"
NUMBERS
100
0.5
-1290
-1.09
Numbers là các con số
BOOLEAN
True
False
Boolean chỉ có giá trị
True (đúng) hoặc
False (sai)
KIỂU DỮ LIỆU (Data types)
6
x=2
name = "VEXCapybara"
CapybaraCute = True
print(x)
print(name)
print(CapybaraCute)
Biến và Kiểu Dữ Liệu
# Đã chiến xong -–>
# <-- Tớ chưa hiểu
7
7
Biến và Kiểu Dữ Liệu
# Đã chiến xong – - >
# Giữ đoạn code phần trên, copy tiếp đoạn code
“thần thánh” này paste bên dưới để robot chạy nè
motor_front_right.spin_to_position(x*100,MM)
motor_front_left.spin_to_position(x*100,MM)
wait(3,SECONDS)
# Tips: Thử thay đổi biến x xem nhé
8
8
RFC2024
8
CHUỖI (String)
+
Nối chuỗi
str()
Chuyển sang chuỗi
len()
Số ký tự
9
x=2
name = "VEXCapybara"
CapybaraCute = True
print("Xin chao " + name)
print("Xin chao " + name *3)
print("VEX" in name)
print("Loopy" in name)
9
CHUỖI (String)
# Đã chiến xong – - >
10
x=2
y=x*2
z=x-y
print(5+5)
print(x,y)
print(z)
print(6 > 7)
print(x > 7)
10
TOÁN TỬ (Operation)
# Đã chiến xong – - >
11
11
Pre-course Python
TOÁN TỬ (Operation)
# Đã chiến xong – - >
# Giữ đoạn code phần trên, copy tiếp đoạn code
“thần thánh” này paste bên dưới để robot chạy nè
motor_front_right.spin_to_position(x*100,MM)
motor_front_left.spin_to_position(x*100,MM)
wait(2,SECONDS)
motor_front_right.spin_to_position(z*100,MM)
motor_front_left.spin_to_position(z*100,MM)
wait(2,SECONDS)
# Tips: Thử thay đổi x,y xem nhé
12
Parts=["Brain","Motor","Wheel"]
#Parts.append("Sensor")
print("co linh kien khong: ", "Sensor" in Parts)
wait(1,SECONDS)
#Thử bỏ dấu thăng đi, lệnh append sẽ thêm
“Sensor" vào danh sách nè!
12
Pre-course Python
DANH SÁCH (List)
# Đã chiến xong – - >
13
print("Chạy")
motor_front_right.spin_to_position(800,MM)
motor_front_left.spin_to_position(800,MM)
wait(3,SECONDS)
print("Khoảng cách: ",distance_1.object_distance(MM),"mm")
if distance_1.object_distance(MM) >= 300:
print("Chưa đụng")
else:
print("Cảnh báo đụng")
wait(1,SECONDS)
# Thử đổi 800 sang 1300 và xem sự khác biệt nhé
13
Pre-course Python
CÂU ĐIỀU KIỆN (IF Statement)
# Đã chiến xong – - >
14
motor_front_right.spin_to_position(1000,MM)
motor_front_left.spin_to_position(1000,MM)
wait(3,SECONDS)
print("Khoảng cách:
"distance_1.object_distance(MM),"mm")
14
Pre-course Python
CÂU ĐIỀU KIỆN (IF - ELIF)
if distance_1.object_distance(MM) >= 1000:
motor_front_left.set_velocity(200, RPM)
motor_front_right.set_velocity(200, RPM)
print("Còn Xa Lắm")
elif distance_1.object_distance(MM) >= 300:
motor_front_left.set_velocity(50, RPM)
motor_front_right.set_velocity(50, RPM)
print("Gần gần đụng")
else:
motor_front_left.set_velocity(10, RPM)
motor_front_right.set_velocity(10, RPM)
print("Cảnh báo đụng")
wait(1,SECONDS)
# Thử đổi -200 sang 0 và 1000 và xem sự khác biệt nhé
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
motor_front_right.spin_to_position(1300,MM)
motor_front_left.spin_to_position(1300,MM)
wait(6,SECONDS)
print("Khoảng cách:
",distance_1.object_distance(MM),"MM")
34
35
36
37
15
15
Pre-course Python
CÂU ĐIỀU KIỆN (IF - ELIF)
# Đã chiến xong – - >
# Thử đổi -200 sang 0 và 1000 và xem sự khác biệt nhé
16
# Di chuyển đến vị trí 1300 mm
def di_chuyen_den_1300():
motor_front_right.spin_to_position(1300,MM)
motor_front_left.spin_to_position(1300,MM)
wait(4,SECONDS)
di_chuyen_den_1300()
16
Pre-course Python
Hàm (Function)
# Đã chiến xong – - >
17
# Di chuyển đến vị trí x mm
x= 1000
def di_chuyen_den(x):
motor_front_right.spin_to_position(x,MM)
motor_front_left.spin_to_position(x,MM)
wait(4,SECONDS)
di_chuyen_den(x)
# Thử thay x bằng 300,500 và 1300
# và xem sự khác biệt
17
Pre-course Python
Hàm (Function)
# Đã chiến xong – - >
18
# Hàm Di chuyển và quay
def di_chuyen_va_quay():
motor_front_left.set_velocity(50, RPM)
motor_front_right.set_velocity(50, RPM)
motor_front_right.spin(FORWARD)
motor_front_left.spin(FORWARD)
wait(2,SECONDS)
motor_front_right.stop()
motor_front_left.stop()
wait(1,SECONDS)
motor_front_right.set_velocity(50, RPM)
motor_front_right.spin(FORWARD)
wait(1.6,SECONDS)
motor_front_right.stop()
wait(1,SECONDS)
18
Pre-course Python
Hàm (Function)
19
# giữ lại hàm def di_chuyen_va_quay() ở trên
# bổ sung vòng lặp for
# để lặp lại thao tác di chuyển và quay 4 lần
for repeat_count in range(4):
di_chuyen_va_quay()
19
Pre-course Python
VÒNG LẶP FOR (For loop)
# Đã chiến xong – - >
20
# giữ lại hàm def di_chuyen_va_quay() ở trên
# xóa vòng lặp for và bổ sung vòng lặp while
# While sẽ lặp lại theo điều kiện
# vd: Di chuyển và quay đến khi pin còn dưới 30
print("Run")
Battery= 100
while Battery>=30:
print("Battery: ",Battery)
Battery = Battery - 15
di_chuyen_va_quay()
print("Battery Low. Completed Driving")
# Battery - 15: mỗi lần thực hiện pin mất 15
20
Pre-course Python
VÒNG LẶP WHILE (While loop)
# Đã chiến xong – - >
21
RFC2024
21
Pre-course Python
Mở Webots
Chiến Python
22
22
23
print("Chạy")
motor_front_right.spin_to_position(800,MM)
motor_front_left.spin_to_position(800,MM)
wait(3,SECONDS)
print("Khoảng cách: ",distance_1.object_distance(MM),"mm")
if distance_1.object_distance(MM) >= 300:
print("Chưa đụng")
else:
print("Cảnh báo đụng")
wait(1,SECONDS)
# Thử đổi 800 sang 1300 và xem sự khác biệt nhé
23
Pre-course Python
test
# Đã chiến xong – - >
24
CS 202
Lập trình Python là gì?
Hướng dẫn máy tính
làm các thao tác từ đơn
giản đến phức tạp
Ngôn ngữ lập trình
Python
Có thể lập trình trên nhiều
nền tảng khác nhau
25
CS 202
BIẾN (Variable)
25
Pre-course Python
print()
XUẤT MÀN HÌNH
x=2
BIẾN
Giá trị
Tên biến
# Đã chiến xong -–>
26
26
RFC2024
26
STRING
"VEXCapybara"
'1562'
String là một tập hợp
các kí tự, chữ
"p"
NUMBERS
100
0.5
-1290
-1.09
Numbers là các con số
BOOLEAN
True
False
Boolean chỉ có giá trị
True (đúng) hoặc
False (sai)
KIỂU DỮ LIỆU (Data types)
# Đã chiến xong -–>
27
while điều_kiện_lặp:
# Công việc lặp lại
for i in range (n):
# Công việc lặp lại
if điều_kiện_a:
# Công việc A
elif điều_kiện_b:
# Công việc B
else:
# Công việc C
def tên_hàm(n):
# Xử lý trong hàm
ĐIỀU KIỆN
VÒNG LẶP
STRING
"Steam for Vietnam"
'1562'
"p"
NUMBERS
100
0.5
-1290
-1.09
BOOLEAN
True
False
123
LIST
gio_hang = [1, 2, 3]
PHÉP TOÁN LOGIC
not
or
and
THAO TÁC CHUỖI
len()
str()
+
CÁC TOÁN TỬ
==
!=><>=
<=
+
%//**
/*-
THAO TÁC DANH SÁCH
len()
append()
gio_hang[0]
range()
HÀM
CÁC KIỂU DỮ LIỆU
28
CS 202
THAO TÁC VỚI CHUỖI (String)
Pre-course Python
28
+
Nối chuỗi
str()
Chuyển sang chuỗi
len()
Số ký tự
position_A = 12
name ='motor A'
info = name +' = '+str(position_A)
print(info)
print('A= '+str(position_A))
print(len(name))
1
2
3
4
5
6
motor A = 12
A= 12
7
29
CS 202
LƯU Ý VỀ CHUỖI TRONG PYTHON
29
Pre-course Python
' '
Chuỗi ký tự một dòng
""""""
Chuỗi ký tự nhiều dòng
" "
name ='motor A'
info ="""
Free speed: 120rpm
Output power: 1.4W
"""
print(name)
print(info)
1
2
3
4
5
6
7
motor A
Free speed: 120rpm
Output power: 1.4W
30
31
CS 202
31
Đây là một sản phẩm trí tuệ có bản quyền thuộc về STEAM for Vietnam. Các bên chỉ được sử dụng với mục đích học
tập, nghiên cứu, và không được quyền sử dụng sản phẩm này nhằm mục đích thu lợi nhuận dù trực tiếp hay gián tiếp.
RFC2024
Pre-course Python
1
Introduction to robotics
Show answer
Auto Play
Slide 1 / 31
SLIDE
Similar Resources on Wayground
28 questions
JWD Introduction to JS
Lesson
•
Professional Development
21 questions
Module 5 Topic 7 and 8 Passing and Navigating Rural Roadways
Lesson
•
KG
27 questions
dil gelişimi
Lesson
•
KG
21 questions
Three Phase Vs Single Phase
Lesson
•
KG
25 questions
Array as Array 9
Lesson
•
KG
26 questions
for while break continue
Lesson
•
KG
27 questions
COMANDOS DOS
Lesson
•
KG
26 questions
Using Google Tools for Engagement
Lesson
•
Professional Development
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
14 questions
Boundaries & Healthy Relationships
Lesson
•
6th - 8th Grade
13 questions
SMS Cafeteria Expectations Quiz
Quiz
•
6th - 8th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
12 questions
SMS Restroom Expectations Quiz
Quiz
•
6th - 8th Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
10 questions
Pi Day Trivia!
Quiz
•
6th - 9th Grade