7、分支語句:if elif elif ... else
age = input("請輸入年齡")
if age >= 18:
print("成年人")
elif age < 0:
print("嬰兒")
else:
print("青少年")
8、邏輯運算符:and or not 表示 與 或 非
9、循環語句
count = 0
while count < 5:
print("count: %d" % count)
count += 1
10 、 字符串輸出格式:
%d表示整型輸出 %06d 表示輸出的數字有六位,不足寫0
%s 表示字符串輸出
%f 表示浮點型輸出,%02f表示小數點後保留兩位數
輸出的字符中如果有要被替換的字符或數字,用%替換。如:print("price is %02f ,money is %d" % (price,money))
11、轉義字符:\+ \- \* \\ \** \t \n 等
12、嵌套循環:
row= 1
while row<= 9:
col = 1
while col <= row:
print("%d * %d = " % (col, row),end="\t")
col += 1
print("")
row += 1