1.day1作業講解

題目答案見day1

2.格式化輸出

%佔位符,s:字串,d:數字

%%只是單純的顯示%(顯示的%是後面的)

 #格式化輸出
# % s d
# name = input('請輸入姓名')
# age = input('請輸入年齡')
# height = input('請輸入身高')
# msg = "我叫%s,今年%s 身高 %s" %(name,age,height)
# print(msg) name = input('請輸入姓名:')
age = input('請輸入年齡:')
job = input('請輸入工作:')
hobbie = input('你的愛好:') msg = '''------------ info of %s -----------
Name : %s
Age : %d
job : %s
Hobbie: %s
------------- end -----------------''' %(name,name,int(age),job,hobbie)
print(msg) name = input('請輸入姓名')
age = input('請輸入年齡')
height = input('請輸入身高')
msg = "我叫%s,今年%s 身高 %s 學習進度為3%%s" %(name,age,height)
print(msg)

3.while else語句

 count = 0
while count <= 5:
count += 1
if count == 3:break print("Loop",count) else:
print("迴圈正常執行完啦")
print("------ out of while loop ------")

注:當while迴圈被break打斷,就不會執行else的結果

4.初始編碼

01010100        新
11010000        開
11010100        一
01100000        家
11000000        看
11000000        看

01010100011101110101011110110
A B C
01000001 01000010 01000011
電報,電腦的傳輸,儲存都是01010101

最早的'密碼本' ascii 涵蓋了英文字母大小寫,特殊字元,數字。
01010101
ascii 只能表示256種可能,太少,
創辦了萬國碼 unicode
    16表示一個字元不行,32位表示一個字元。
    A  01000001010000010100000101000001
    B  01000010010000100100001001000010
    我 01000010010000100100001001000010
Unicode 升級 utf-8  utf-16 utf-32
    8位 = 1位元組bytes
    utf-8 一個字元最少用8位去表示,英文用8位  一個位元組
          歐洲文字用16位去表示                兩個位元組
          中文用24 位去表示                   三個位元組
    utf-16 一個字元最少用16位去表示

gbk 中國人自己發明的,一箇中文用兩個位元組 16位去表示。

11000000

1bit    8bit = 1bytes
1byte   1024byte = 1KB
1KB     1024kb = 1MB
1MB     1024MB = 1GB
1GB     1024GB = 1TB

5.邏輯運算

1.優先順序 () > not > and > or

2.int ----> bool (數字轉換成布林值) 非零轉換成bool True 0 轉換成bool 是False

3.x or y x True,則返回x

4.x and y x True,則返回y

 # and or not
#優先順序 () > not > and > or
#print( 2 > 1 and 1 < 4 )
#print ( 2 > 1 and 1 < 4 or 2 < 3 and 9 > 6 or 2 < 4 and 3 < 2)
# T or T or F
#T or F
# print(3>4 or 4<3 and 1==1) # F
# print(1 < 2 and 3 < 4 or 1>2) # T
# print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) # T
# print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) # F
# print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F
# print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F #ps int ----> bool (數字轉換成布林值) 非零轉換成bool True 0 轉換成bool 是False
# print(bool(2))#T
# print(bool(-2))#T
# print(bool(0))#F
# #bool --->int
# print(int(True)) # 1
# print(int(False)) # 0 '''x or y x True,則返回x'''
# print(1 or 2) # 1
# print(3 or 2) # 3
# print(0 or 2) # 2
# print(0 or 100) # 100 # print(2 or 100 or 3 or 4) # 2 # # print(0 or 4 and 3 or 2) # x and y x True,則返回y
# # print(1221Q 1234
# ,。and 2)
# # print(0 and 2)
print(2 or 1 < 3)
print(3 > 1 or 2 and 2)