運算符與編碼

---恢復內容開始---編碼

  1. while循環 (難點)spa

        while 條件:設計

            循環體(break, continue)code

    continue 中止當前本次循環. 繼續執行下一次循環blog

    break 完全結束一個循環utf-8

while True:
    n= int(input("輸入一個數字"))
    if n> 66:
        print("猜大了")
        continue
    if n<66:
        print("猜小了")
        continue
    if n==66:
        print("正確")
        break

 2. 格式化輸出 %s    %dci

        f"{變量}"unicode

    

count = 2
while count >= 0:
    password = input("用戶登陸,請輸入密碼:")
    print("輸入錯誤,你還有%s機會"%(count))
    count = count-1

 

  3. 運算符 and or not  (難點)input

        運算順序: ()=> not  => and =>orit

   and : 而且. 左右兩端同時爲真. 結果才能是真
   or : 或者. 左右兩端有一個是真. 結果就是真
   not : 非. 非真既假, 非假既真 不真-> 假  不假 -> 真
例如:not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6

 

    4. 初識編碼 gbk unicode utf-8

        1. ascii   8bit  1byte(字節)  256個碼位 只用到了7bit, 用到了前128個 最前面的一位是0

        2. 中國人本身對計算機編碼進行統計. 本身設計. 對ascii進行擴展 ANSI 16bit -> 清華同方 -> gbk

            GBK 放的是中文編碼. 16bit  2byte 兼容ascii

        3. 對全部編碼進行統一. unicode. 萬國碼.  32bit. 4byte. 夠用了可是很浪費

 

        4. utf-8 可變長度的unicode

            英文: 1byte

            歐洲文字: 2byte

            中文: 3byte

 字節(byte)
    1byte = 8bit
    1kb = 1024byte
    1mb = 1024kb
    1gb = 1024mb
    1tb = 1024gb
    1pb = 1024tb

 

 

最後,來一個小小的練習吧!!!!!!

 計算 1-100之間全部的數的和
sum = 0                       # sum: 0 + 1 + 2 + 3 + 4....99 + 100
count = 1                    # count: 1, 2, 3, 4, 99,100, 101
while count <= 100:
sum = sum + count    # 累加運算
count = count + 1
print(sum)
相關文章
相關標籤/搜索