运算符与编码

---恢复内容开始---

  1. while循环 (难点)

        while 条件:

            循环体(break, continue)

    continue 停止当前本次循环. 继续执行下一次循环

    break 彻底结束一个循环

while True:
    n= int(input("输入一个数字"))
    if n> 66:
        print("猜大了")
        continue
    if n<66:
        print("猜小了")
        continue
    if n==66:
        print("正确")
        break

 2. 格式化输出 %s    %d

        f"{变量}"

    

count = 2
while count >= 0:
    password = input("用户登录,请输入密码:")
    print("输入错误,你还有%s机会"%(count))
    count = count-1

  3. 运算符 and or not  (难点)

        运算顺序: ()=> not  => and =>or

   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)

猜你喜欢

转载自www.cnblogs.com/selina1997/p/10028466.html