zoukankan      html  css  js  c++  java
  • python学习第二天

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

    1.while 条件:

    else:

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

    3. 格式化输出
            %s 占位字符串  全能的 什么都能接
            %d 占位数字
       如果你的字符串中出现了%s这样的格式化的内容. 后面的%都认为是格式化.如果想要使用%. 需要转义 %%


    3.初始编码

    电报,电脑的传输,存储都是01010101
    最早的'密码本' ascii 涵盖了英文字母大小写,特殊字符,数字。
    8位 = 1字节bytes
    utf-8 一个字符最少用8位去表示,英文用8位 一个字节
    欧洲文字用16位去表示 两个字节
    中文用24 位去表示 三个字节
    utf-16 一个字符最少用16位去表示

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

    ascii 只能表示256种可能,太少,
    创办了万国码 unicode
    一个字节表示所有英文,特殊字符,数字等等


    4.运算符
    
    
    #优先级,()> 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))
    # print(bool(-2))
    # print(bool(0))
    # #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(0 or 4 and 3 or 2)  #3
    print(2 or 1 < 3)  #2
    print(1 > 2 and 3 or 4 and 3 < 2) #False

    作业 1

    1、判断下列逻辑语句的True,False.

    1),1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6   T
    2)not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6   F
    3)1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8 and 4 > 6 or 3 < 2  F

    2、求出下列逻辑语句的值。   

    1),8 or 3 and 4 or 2 and 0 or 9 and 7     8

    2),0 or 2 and 3 and 4 or 6 and 0 or 3     4

    3),5 and 9 or 10 and 2 or 3 and 5 or 4 or 5        9 

    写代码:计算 1 - 2 + 3 ... + 99 中除了88意外所有数的总和?

    解法1:

    count = 1
    sum = 0
    while count<100:
        if count == 88:
            count +=1
            continue
        elif count % 2 == 0:
            sum -= count
        elif count % 2 == 1:
            sum += count
        count += 1
    print(sum)

    解法2:

    count = 0
    sum = 0
    i = -1
    while count < 99:
        count += 1
        i = -i
        if count == 88:
            continue
        else:
            sum = sum+count*i
    print(sum)
    
    
    
    
    
    



  • 相关阅读:
    设计模式详细系列教程 (三)以网上购物通用的订单流程 详解状态模式
    DIV +CSS 系列详细教程 (一)初识
    JAVA JDK环境变量的配置
    SCM软件配置管理 (二) SVN管理平台搭建以及详细设置
    设计模式详细系列教程 (四) 无处不在的单例模式
    Java、JavaScript、asp.net 、jquery 详细分析
    牛腩新闻发布系统 (6) 在线浮动的客服功能
    牛腩新闻发布系统 (4)验证码的生成
    UML系列 (六)如何提取用例技术?
    牛腩新闻发布系统 (5) 总结
  • 原文地址:https://www.cnblogs.com/faded8679/p/10167338.html
Copyright © 2011-2022 走看看