• while 循环,格式化输出和运算编码


    今日内容
    1.while循环
    while Ture:
                content = input ("请输入你要喷的内容",输入Q退出)
                if content == ""
                    continue(继续,如果是break就是直接退出循环)
                if content == "Q":
                     break
                print("你对打野说",content)
    最多说三次,通过count的大小来对册数进行限制
    count = 1
    while count <= 3:
     
        # count = 1  # 次数, 死循环
        content = input("请输入你要喷的内容")
        print("你要喷的内容:", content)
     
        # 改变count
        count = count + 1
    打印出1到100的数
    count = 1
    while count <= 100:
        print(count)
        count = count + 1
    打印出1-100的和
    sum = 0
    count = 1
    while count <= 100:
        sum = sum + count(sum += count)
        count = count + 1
    print(sum)
    打出1-100的奇数
    count = 1
    while count <= 100:
        print(count)
        count = count + 2
    count = 1
     while count <= 100:
        print(count)
        count = count + 2
    输入你知道的人名,如果输入人名是:xxx,输出的也是xxx
    while True:
        name = input("你知道的人名,输入不知道直接退出:")
        if name == ("不知道"):
           continue
        print("你知道的名字:", name)
    continue :  停止当前本次循环,继续执行写一次循环,不会彻底终端循环
    break :  彻底干掉一个循环
    能退出循环:    1.break        2.改变循环条件
    2.格式化输出   %s  %d
    %s  表示字符串的占位,全能的占位
    坑:  如果这句话使用了格式化输出,%就是占位,如果想显示正常的%,输入%%转义
    name = input("请输入你的名字:")    #input里面内容是字符串
    address = input("请输入你来自哪里:")
    wife = input("请输入你的老婆:")
    notlike = input("请输入你不喜欢的明星:")
     
    print("我叫"+name+", 我来自"+address+", 我老婆是"+wife+", 我不喜欢"+notlike)  
      #字符串的拼接
    需要掌握的内容
    #格式化输出
    print("我叫%s, 我来自%s, 我老婆是%s, 我不喜欢%s" % (name, address, wife, notlike))
    # 新版本的格式化输出
    print(f"我叫{name}, 我来自{address}, 我老婆是{wife}, 我不喜欢{notlike}")
    %d  占位数字,只能是数字
    %s 表示字符串的占位 . 全能的占位.
    print("周杰伦今年%s岁了" % 18)
    # %d 占位数字. 只能放数字
    print("周杰伦去年%d岁了" % 16)
    print("周杰伦去年%d岁了" % "16") # 报错
    3.运算符   
    a.算是运算
    +-*/ %**//
    b.比较运算
    print(3<>3)不等于
    c.赋值运算
    d.逻辑运算
    and :并且.左右来两端同时为真,结果才能是真
    or: 或者,左右两端有一个为真,结果就是真
    not:  非,非真既假,非假既真     不真=假    不假=真
    混合运算:运算顺序----()=>not=> and  =>or   当出现相同的运算的时候,从左往右算
    print(3 > 2 or 5 < 7 and 6 > 8 or 7 < 5)  # True
    print(3 > 4 or 4 < 3 and 1 == 1)  # False
    print(1 < 2 and 3 < 4 or 1 > 2)  # True
    print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) # True
    print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) # False
    print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # False
    print((not 2 > 1 and 3 < 4) or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # False
    当出现x or y的时候,判断x是否是0.如果x=0 then y   否则返回x
    print(1 or 2) # 1
    print(0 or 2) # 2
    print(3 or 0) # 3
    print(4 or 0) # 4
    当出现x and y的时候,和or相反的
    print(1 and 2) # 2
    print(0 and 3) # 0
    print(3 and 0) # 0
    print(4 and 0) # 0
    面试用的60%
    False 当成0来看
    print(False and 1)
    print(3 > 5 or 5 < 6 and 7)
    print(4 > 5 or 7 and 8 < 6 or 3 and 4)
    e.成员运算:
    content = input("请输入你的评论:")
    if "马化腾" in content: # content中是否包含了xxx
        print("你的评论不合法")
    else:
        print("你的评论是合法的")
     
    ad = input("请输入你的广告:")
    if "最" in ad or "第一" in ad or "全球" in ad:
        print("不合法的")
     
    else:
        print("合法的")
    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
  • 相关阅读:
    SpringCloud-服务注册与实现-Eureka创建服务注册中心(附源码下载)
    SpringCloud -创建统一的依赖管理
    Mysql、Oracle、SQLServer等数据库参考文档免费分享下载
    DevExpress的图形按钮菜单栏控件WindowsUIButtonPanel的布局、使用和设置按钮的点击事件
    Winform中设置ZedGraph鼠标滚轮缩放的灵敏度以及设置滚轮缩放的方式(鼠标焦点为中心还是图形中心点)
    Winform中设置多条Y轴时新增的Y轴刻度不显示问题解决
    Winforn中设置ZedGraoh的GraphPane恢复到初始比例大小
    Winform中设置ZedGraph多条Y轴时与多条曲线一一对应
    Winform中设置ZedGraph多条Y轴时坐标轴左右显示设置
    一、关于a标签伪类中的visited不起作用问题
  • 原文地址:https://www.cnblogs.com/yanghongtao/p/10028808.html
Copyright © 2020-2023  润新知