-
Tuần 1 - Ngày 10 tháng 7 năm 2019
- Giới thiệu về khóa học
- Hướng dẫn viết chương trình Python trên web
- Hướng dẫn sử dụng PyCharm
- Tổng quan về Python
- Kỹ năng sử dụng Google search
- Viết tài liệu kỹ thuật dùng Markdown
- Hàm xây dựng sẵn trong Python – math và random
- Cài đặt các công thức toán cơ bản
- Xây dựng hàm trong python
- Điều kiện if-else
- Những lỗi thường gặp trong Python
- Reading assignment
-
Tuần 2 - Ngày 17 tháng 7 năm 2019
-
Tuần 3 - Ngày 24 tháng 7 năm 2019
-
Tuần 4 - Ngày 31 tháng 7 năm 2019
-
Tuần 5 - Ngày 7 tháng 8 năm 2019
-
Advanced Python
-
Tuần 6 - Ngày 14 tháng 8 năm 2019
-
Tuần 7 - Ngày 28 tháng 8 năm 2019
-
Tuần 8
-
Tuần 9
Những lỗi thường gặp trong Python
Lỗi 1: Lỗi sử dụng biến chưa được khai báo
# aivietnam.ai # Lỗi sử dụng biến chưa được khai báo # khai báo biến a = 5 a = 5 # thực hiên a + b, sau đó lưu vào biến c c = a + b # in giá trị c print(c)
Kết quả
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-1-eae96ee94f9f> in <module> 6 7 # thực hiên a + b, sau đó lưu vào biến c ----> 8 c = a + b 9 10 # in giá trị c NameError: name 'b' is not defined
Lỗi 2: Lỗi viết sai tên hàm
# aivietnam.ai # Lỗi viết sai tên hàm # khai báo biến a = 5 a = 5 # in giá trị a Print(a)
Kết quả
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-2-f09db6b2bf7e> in <module> 6 7 # in giá trị a ----> 8 Print(a) NameError: name 'Print' is not defined
Lỗi 3: Lỗi khai báo chuỗi (string) sai
# aivietnam.ai # Lỗi khai báo chuỗi (string) sai # khai báo biến chuỗi s s = 'Hello AIVIETNAM" # in giá trị s print(s)
Kết quả
File "<ipython-input-3-96feed73c6b1>", line 5 s = 'Hello AIVIETNAM" ^ SyntaxError: EOL while scanning string literal
Lỗi 4: Lỗi chia cho số 0
# aivietnam.ai # Lỗi chia cho số 0 # khai báo biến a và b a = 5 b = 0 # tính giá trị c bằng a chia cho b c = a / b # in giá trị c print(c)
Kết quả
--------------------------------------------------------------------------- ZeroDivisionError Traceback (most recent call last) <ipython-input-4-298e1112d534> in <module> 7 8 # tính giá trị c bằng a chia cho b ----> 9 c = a / b 10 11 # in giá trị c ZeroDivisionError: division by zero
Lỗi 5: Lỗi dùng phép toán không phù hợp với kiểu dữ liệu (1)
# aivietnam.ai # Lỗi dùng phép toán không phù hợp với kiểu dữ liệu # khai báo biến chuỗi s s = 'AI' # khai báo biến n có kiểu integer n = 5 # tính giá trị c c = s + n # in giá trị c print(c)
Kết quả
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-5-f1e2455fae51> in <module> 9 10 # tính giá trị c ---> 11 c = s + n 12 13 # in giá trị c TypeError: must be str, not int
Lỗi 6: Lỗi dùng phép toán không phù hợp với kiểu dữ liệu (2)
# aivietnam.ai # Lỗi dùng phép toán không phù hợp với kiểu dữ liệu (2) # khai báo biến chuỗi s s = 'AI' # khai báo biến n có kiểu integer n = 5 # tính giá trị c c = n + s # in giá trị c print(c)
Kết quả
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-8-cecd5289546d> in <module> 9 10 # tính giá trị c ---> 11 c = n + s 12 13 # in giá trị c TypeError: unsupported operand type(s) for +: 'int' and 'str'
Lỗi 7: Lỗi indentation
# aivietnam.ai # Lỗi indentation # khai báo biến a và b a = 5 b = 6 # thực hiên a + b, sau đó lưu vào biến c c = a + b # in giá trị c print(c)
Kết quả
File "<ipython-input-7-31f64166c395>", line 6 b = 6 ^ IndentationError: unexpected indent
Lỗi 8: Lỗi thiếu ngoặc đóng/mở
# aivietnam.ai # Lỗi thiếu ngoặc đóng/mở import math number = 20.2 print(math.floor(number) print(math.pi)
Kết quả
File "<ipython-input-15-920005110c33>", line 8 print(math.pi) ^ SyntaxError: invalid syntax
Lỗi 9: Lỗi thiếu ngoặc khi dùng print
# aivietnam.ai # Lỗi thiếu ngoặc khi dùng print print "aivietnam.ai"
Kết quả
File "<ipython-input-3-a46b1c9e05ed>", line 4 print "aivietnam.ai" ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print("aivietnam.ai")?
Lỗi 10: Lỗi khai báo module không tồn tại
# aivietnam.ai # Lỗi khai báo module không tồn tại import mymodule print("aivietnam.ai")
Kết quả
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) <ipython-input-5-1b242c59080b> in <module> 2 # Lỗi khai báo module không tồn tại 3 ----> 4 import mymodule 5 6 print("aivietnam.ai") ModuleNotFoundError: No module named 'mymodule'
Lỗi 11: Lỗi out-of-range (1)
# aivietnam.ai # Lỗi out-of-range l = [1, 2, 3, 4, 5] print(l[0]) print(l[5])
Kết quả
1 --------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-6-b8c53176edc0> in <module> 4 l = [1, 2, 3, 4, 5] 5 print(l[0]) ----> 6 print(l[5]) IndexError: list index out of range
Lỗi 12: Lỗi out-of-range (2)
# aivietnam.ai # Lỗi out-of-range name = "aivietname.ai" print(name[0]) print(name[50])
Kết quả
a --------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-7-357ff533411a> in <module> 4 name = "aivietname.ai" 5 print(name[0]) ----> 6 print(name[50]) IndexError: string index out of range
Lỗi 13: Lỗi key không tồn tại
# aivietnam.ai # Lỗi key không tồn tại dict = {'1':'Python', '5':'C++'} print(dict['1']) print(dict['5']) print(dict['2'])
Kết quả
Python C++ --------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-11-cd160b2a5e34> in <module> 5 print(dict['1']) 6 print(dict['5']) ----> 7 print(dict['2']) KeyError: '2'
Lỗi 14: Lỗi thiếu dấu : (1)
# aivietnam.ai # Lỗi thiếu dấu : number = 15 if number < 10 print("A small number") else: print("A large number")
Kết quả
File "<ipython-input-15-fedf173614ac>", line 5 if number < 10 ^ SyntaxError: invalid syntax
Lỗi 15: Lỗi thiếu dấu : (2)
# aivietnam.ai # Lỗi thiếu dấu : number = 15 if number < 10: print("A small number") else print("A large number")
Kết quả
File "<ipython-input-16-699752908646>", line 7 else ^ SyntaxError: invalid syntax
Lỗi 16: Lỗi thay đổi giá trị của một tuple
# aivietnam.ai # Lỗi thay đổi giá trị của một tuple t = (1,2,3,4) t[2] = 2
Kết quả
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-1-24607f50b9ee> in <module> 3 4 t = (1,2,3,4) ----> 5 t[2] = 2 TypeError: 'tuple' object does not support item assignment
Lỗi 17: Lỗi cố gắng lấy phần tử từ dictionary rỗng
# aivietnam.ai # Lỗi cố gắng lấy phần tử từ dictionary rỗng dict = {'1':'Python', '5':'C++'} item1 = dict.popitem() item2 = dict.popitem() item3 = dict.popitem()
Kết quả
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-6-40b67d40ba0f> in <module> 5 item1 = dict.popitem() 6 item2 = dict.popitem() ----> 7 item3 = dict.popitem() KeyError: 'popitem(): dictionary is empty'
Lỗi 18: Lỗi lấy căn cho một số âm
import math number = -4 print(math.sqrt(number))
Kết quả
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-8-f25b4b744f6e> in <module> 2 3 number = -4 ----> 4 print(math.sqrt(number)) ValueError: math domain error
Lỗi 19: Lỗi đọc file không tồn tại
# aivietnam.ai # Lỗi đọc file không tồn tại my_file = open("file.txt","r") print(my_file)
Kết quả
--------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) <ipython-input-13-73d8e6dda2db> in <module> 2 # Lỗi đọc file không tồn tại 3 ----> 4 my_file = open("file.txt","r") 5 print(my_file) FileNotFoundError: [Errno 2] No such file or directory: 'file.txt'
Lỗi 20: Lỗi import thư viện chưa cài đặt
# aivietnam.ai # Lỗi import thư viện chưa cài đặt # import pytorch import torch print(torch.cuda.is_available())
Kết quả
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) <ipython-input-14-680f8ea2b256> in <module> 1 # import thử viện pytorch ----> 2 import torch 3 4 print(torch.cuda.is_available()) ModuleNotFoundError: No module named 'torch'
Lỗi 21: Lỗi tìm vị trí của một string không có trong một string khác
# aivietnam.ai # Lỗi tìm vị trí của một string không có trong một string khác my_string = "Đây là bài học của AI VIETNAM" my_string.index("hello")
Kết quả
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-1-9d5c7da27233> in <module> 3 4 my_string = "Đây là bài học của AI VIETNAM" ----> 5 my_string.index("hello") ValueError: substring not found