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

    首先,复习了昨天的作业:

    #1、使用while循环输入 1 2 3 4 5 6 8 9 10
    '''
    count = 0
    while count < 10:
    count += 1 # count = count + 1
    if count == 7:
    print(' ')
    else:
    print(count)

    count = 0
    while count < 10:
    count += 1 # count = count + 1
    if count == 7:
    continue
    print(count)
    '''
    #3、输出 1-100 内的所有奇数
    #方法一:
    # count = 1
    # while count < 101:
    # print(count)
    # count += 2
    #方法二:
    # sum = sum - count
    # else:
    # sum = sum + count
    # count += 1
    # print(sum)

    #6、用户登陆(三次机会重试)
    #input 心中有账号,密码 while

    i = 0
    while i < 3:
    username = input('请输入账号:')
    password = int(input('请输入密码:'))
    if username == '咸鱼哥' and password == 123:
    print('登录成功')
    else:
    print('登录失败请重新登录')
    i += 1
    然后,学习了格式化输出
    #格式化输出
    # % 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%%d" %(name,age,height)
    print(msg)
    学习了 while else 循环
    count = 0
    while count <= 5 :
    count += 1
    if count == 3:break
    print("Loop",count)
    else:
    print("循环正常执行完啦")
    print("-----out of while loop ------")

    之后学习了初始编码知识
    电报,电脑的传输,存储都是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

    最后学习了逻辑运算
    #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))
    # 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(2 or 100 or 3 or 4) # 2

    # print(0 or 4 and 3 or 2)
    '''x and y x True,则返回y'''
    # print(1 and 2)
    # print(0 and 2)
    print(2 or 1 < 3)
    print(3 > 1 or 2 and 2)。


    课后作业如下

     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 or 4 or 0 or 7 8
    # 2),0 or 2 and 3 and 4 or 6 and 0 or 3
    # 0 or 4 or 0 or 3 4
    # 3),5 and 9 or 10 and 2 or 3 and 5 or 4 or 5
    # 9 or 2 or 5 or 4 or 5 9
    # 3、下列结果是什么?
    # 1)、6 or 2 > 1 6
    # 2)、3 or 2 > 1 3
    # 3)、0 or 5 < 4 F
    # 4)、5 < 4 or 3 3
    # 5)、2 > 1 or 6 T
    # 6)、3 and 2 > 1 T
    # 7)、0 and 3 > 1 0
    # 8)、2 > 1 and 3 3
    # 9)、3 > 1 and 0 0
    # 10)、3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2
    # T and 2 or T and 3 and 4 or T
    # 2 or 4 or T 2
    # 4. 简述变量命名规范
    # 必须由数字,字母,下划线组成,且不能数字开头
    # 不能是python中的关键词
    # 不能用汉字,拼音
    # 变量具有可描述性

    # 5. name = input(“>>>”) name变量是什么数据类型?
    #str 字符串

    # 6. if条件语句的基本结构?
    # if 条件:
    # 结果


    # if 条件:
    # 结果
    # else:
    # 结果
    #
    #
    # if 条件:
    # 结果
    # elif 条件:
    # 结果
    # elif 条件:
    # 结果
    #
    #
    # if 条件:
    # if 条件:
    # 结果
    # else:
    # 结果
    # else:
    # 结果



    # 7. while循环语句基本结构?
    # while 条件:
    # 循环体

    # 8. 写代码:计算 1 - 2 + 3 ... + 99 中除了88意外所有数的总和?
    # count = 1
    # sum = 0
    # while count <= 99:
    # if count % 2 == 0 and count != 88:
    # sum = sum - count
    # elif count ==88:
    # sum = sum
    # else:
    # sum = sum + count
    # count += 1
    # print (sum)

    # 9. ⽤户登陆(三次输错机会)且每次输错误时显示剩余错误次数(提示:使
    # ⽤字符串格式化)
    # count = 1
    # while count <= 3:
    # username = input('请输入用户名')
    # password = input('请输入密码')
    # if username == '徐博华' and password =='123':
    # print ('登陆成功')
    # break
    # else:
    # print ('请重新登陆')
    # print ('您还有'+str(3-count)+'次机会')
    # count += 1


    # 10. 简述ascii、unicode、utf-8编码关系?
    # ascii 只有八位 共有256种组合,用来表示英文字母、数字和特殊字符
    # unicode 32位表示 一个字符
    # 由于unicode32位表示一个字符太浪费,升级成为utf-8一个字符最少用8位去表示,英文用8位 一个字节
    # 欧洲文字用16位去表示 两个字节
    # 中文用24 位去表示 三个字节
    # # 11. 简述位和字节的关系?
    # 位:二进制位(bit)是计算机存储信息的基本单位,代表1个二进制数位,其值为0或1。
    # 字节:8个连续的二进制位为一个字节,可以存放1个西文字符的编码。

    # 12. “⽼男孩”使⽤UTF-8编码占⽤⼏个字节?使⽤GBK编码占⼏个字节?
    # unicode 中英文都是两个字节
    # utf-8 英文一个字节,中文3个字节
    # GBK 英文一个字节 中文两个字节
    # ‘老男孩’用utf-8编码占9个字节,用GBK编码占六个字节
    # 13. 制作趣味模板程序需求:等待⽤户输⼊名字、地点、爱好,根据⽤户的
    # 名字和爱好进⾏任意现实 如:敬爱可亲的xxx,最喜欢在xxx地⽅⼲
    # xxx
    # name = input ('请输入姓名:')
    # ad = input ('请输入地址:')
    # hobbie = input ('请输入爱好:')
    # msg = "敬爱可亲的%s,最喜欢在%s地方干%s"%(name,ad,hobbie)
    # print (msg)
    # 14. 等待⽤户输⼊内容,检测⽤户输⼊内容中是否包含敏感字符?如果存在
    # 敏感字符提示“存在敏感字符请重新输⼊”,并允许⽤户重新输⼊并打印。敏
    # 感字符:“⼩粉嫩”、“⼤铁锤”
    #
    # a = "小粉嫩"
    # b = "大铁锤"
    # while True:
    # c = input("请输入一个你喜欢的一段话:")
    # if c != a and c != b:
    # print(c)
    # break
    # else:
    # print("存在敏感字符请重新输⼊")



    # 15. 单⾏注释以及多⾏注释?
    # 单行注释指在注释行前加 #注释
    # 多行注释指在注释前后加 '''注释'''或"""注释"""
    # 16. 简述你所知道的Python3和Python2的区别?
    # python2 源代码不标准,混乱 重复较多
    # python3 源代码统一标准,去除重复代码
    # 17. 看代码书写结果:
    # a = 1>2 or 4<7 and 8 == 8
    #a = F or T and T True
    # print(a)
    # 18.continue和break区别?
    #continue 表示重新开始循环
    #break 表示跳出循环
    # 19.看代码书写结果: a= 12&127 print(a)
    #127
    #
    # Day3默写代码:
    # Bit,Bytes,Kb,Mb,Gb,Tb之间的转换关系。
    # Unicode,utf-8,gbk,每个编码英文,中文,分别用几个字节表示。
    # unicode 中英文都是两个字节
    # utf-8 英文一个字节,中文3个字节
    # GBK 英文一个字节 中文两个字节
  • 相关阅读:
    如何使用Win32API绘制树
    MSD_radix_sort
    Radix Sort
    Computer Science: the Big Picture
    天问之Linux内核中的不明白的地方
    viewController备注
    loadView、viewDidLoad及viewDidUnload的关系(转)
    iOS 中的视图函数 init initwithnib viewDidLoad viewWillAppear的总结
    做ios工程时,把UI从xib移动到代码中遇到的问题
    嘟嘟三期的所学所想
  • 原文地址:https://www.cnblogs.com/xubohua/p/8053692.html
Copyright © 2011-2022 走看看