PYTHON
BT NM NGÀNH CNTT
FILE DRIVE:
LINK
BAI TAP PYTHON
NOTE
Data type and Library:
string :str
integer :int
float :float
boolean :bool - true - false
pip install pygame
boolean :bool - true - false
unsupported: ko ho tro
operand :cac toan tu + - * /
concactenate: noi hai cai lai voi nhau
prompt: muon nguoi khac, nguoi dung nhap vao cai gi
constant variable: bien ko doi duoc// luon luon viet hoa
naming convention: quy dinh dat ten
fraction: phan so
numerator: tu so
denominator: mau so
devide: chia
# comment--
two string can concatenation by plus
input function always returns value string must cast if you want to return another data type // phải ép kiểu nếu muốn trả về kiểu dữ liệu khác
cast integer
a = input()
a = int(a) // overwrite - viet de
lam tron so float use function EX:
hight = round(number,lam tron den phan thap phan so may)
string format:
EX: print("you are " + str(age) + " years old in " + str(CURRENT_YEAR))
--> print("you are {0} years old in {1}".format(age,CURRENT_YEAR))
print("\n")
: xuong dong: new line character
print("your fistname: ")
firstname = intput() // string
----> firstname = intput("your fistname: ")
BOOLEAN has 3 keywork - True,False,None
for loop:
for i in range(0,5):
print(i)
range(0,5)
--> 0,1,2,3,4 == range(5) : tu 0 den so do
range(0,5,2)
--> 0,2,4
range(0,6,2)
-->0,2,4 (because from 0 to 5)
continue
: bỏ qua vòng lặp hiện tại
break
: bỏ qua tất cả vòng lặp phía sau, hủy luôn nó
* print the same line in for loop
ex: for i in range(10):
print("very", end=" ")
or not in for loop: same as
using while de nhap den khi dung:
ex:
while True:
gioitinh = input("Are you male(yes/no): ")
if (gioitinh = "yes" or giotinh = "no"):
break
use list
answers_list = ["yes","no","y","n"]
while True:
gioitinh = input("Are you male(yes/no): ")
if (gioitinh in answers_list):
break
len(list)
:do dai cac phan tu cua list