zoukankan      html  css  js  c++  java
  • Python基础题 2

    1. 判断下列逻辑语句的True,False.
    (1) 1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6
    True
    (2) not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6
    False

    2. 求出下列逻辑语句的值。
    (1) 8 or 3 and 46 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、下列结果是什么?
    (1) 6 or 2 > 1
    6
    (2) 3 or 2 > 1
    3
    (3) 0 or 5 < 4
    False
    (4) 5 < 4 or 3
    3
    (5) 2 > 1 or 6
    True
    (6) 3 and 2 > 1
    True
    (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
    2

    4. 简述变量命名规范
    变量要以数字、下划线或者字母任意组合,且不能以数字开头;
    不能以关键字命名;
    一般不以中文以及汉字拼音命名;
    常量一般全部是大写;
    命名要有意义,不宜过长。

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

    6. if条件语句的基本结构?
    (1) if 条件:
    代码块
    (2) if 条件:
    代码块
    else:
    代码块
    (3) if 条件:
    代码块
    elif 条件:
    代码块
    ...
    else:
    代码块
    (4) if 条件:
    代码块
    if 条件:
    代码块
    else:
    代码块
    else:
    代码块

    7. while循环语句基本结构?
    (1) while 条件:
    代码块
    (2) while 条件:
    代码块
    else:
    代码块
    PS:当遇到continue时,跳出本次循环,继续下次循环;
    当遇到break时,直接跳出while循环,且不再执行else语句。

    8. 写代码:计算 1 - 2 + 3 ... + 99 中除了88以外所有数的总和?
    count = 0
    sum = 0
    power = 0
    while count < 99:
    count += 1
    sum = sum + count*(-1)**power
    power += 1
    print(sum + 88)


    改:计算 1 - 2 + 3 ... - 99 中除了88以外所有数的总和?(正负号规律不变)
    count = 0
    sum = 0
    power = 0
    while count < 99:
    if count == 87:
    count += 1
    continue
    else:
    count += 1
    sum = sum + count*(-1)**power
    power += 1
    print(sum)

    9. 用户登陆(三次输错机会)且每次输错误时显示剩余错误次数(提示:使用字符串格式化)
    user_name = 'admin'
    password = 'admin'
    count = 3
    while count >= 1:
    name = input('请输入账号:')
    paw = input('请输入密码:')
    count -= 1
    if name == user_name:
    if paw == password:
    print('登陆成功!')
    break
    elif count == 0:
    print('三次机会已用完,请12小时后重新登录。')
    else:
    print('输入密码错误!还有%s次机会' % (str(count)))
    elif count == 0:
    print('三次机会已用完,请12小时后重新登录。')
    else:
    print('该用户不存在!还有%s次机会'% (str(count)))

    10. 简述ascii、unicode、utf-8编码关系?
    ASCII码:美国最初编码,只有7位,但防止以后增加,所以定为8位,可是一直没有增加。
    unicode编码:万国码,为了解决全球化的文字问题而创建。一个中文用4个字节表示,太浪费(中文9万多字)
    utf-8编码:一个中文3个字节表示
    GBK编码:只在国内使用,一个中文用2个字节表示

    11. 简述位和字节的关系?
    8位(bit) == 一个字节(Byte)
    bit,Byte,KB,MB,GB,TB之间的转换关系:
    8b == 1B
    1024B == 1KB
    1024KB == 1MB
    1024MB == 1GB
    1024GB == 1TB

    12. “老男孩”使用UTF-8编码占用几个字节?使用GBK编码占几个字节?
    “老男孩”使用UTF-8编码占用9个字节
    “老男孩”使用GBK编码占用6个字节

    13. 制作趣味模板程序需求:等待用户输入名字、地点、爱好,根据用户的名字和爱好进行任意实现 如:敬爱可亲的xxx,最喜欢在xxx地方干xxx
    name = input('请输入姓名:')
    place = input('喜欢的地点:')
    hobby = input('你的爱好:')
    tem = '敬爱可亲的%s,最喜欢在%s地方干%s'%(name, place ,hobby)
    print(tem)

    14. 等待用户输入内容,检测用户输入内容中是否包含敏感字符?如果存在敏感字符提示“存在敏感字符请重新输入”,并允许用户重新输入并打印。敏感字符:“小粉嫩”、“大铁锤”
    message = input('请输入内容:')
    while message == '小粉嫩' or message == '大铁锤':
    print('存在敏感字符请重新输入')
    message = input('请输入内容:')
    else :
    print('1')

    15. 单行注释以及多行注释?
    单行注释:“ ” 或 ' '
    多行注释:“”“ ”“” 或''' '''

    16. 简述你所知道的Python3和Python2的区别?
    Python2:由龟叔团队开发,源码杂而乱,且有重复内容,违背了Python的宗旨。默认编码方式是ASCII码,读取中文时会乱码
    Python3:由龟叔开发,遵循“优雅,明确,简单”,默认编码方式是utf-8,读取中文时不会乱码

    17. 看代码书写结果:
    a = 1>2 or 4<7 and 8 == 8
    print(a)

    结果:True

    18. continue 和 break 的区别?
    continue:结束本次循环,继续下一次的循环;
    break:直接跳出循环。

    19. 看代码书写结果:
    a = 12 and 127
    print(a)

    结果:127

  • 相关阅读:
    Win10 UWP Tile Generator
    Win10 BackgroundTask
    UWP Tiles
    UWP Ad
    Win10 build package error collections
    Win10 八步打通 Nuget 发布打包
    Win10 UI入门 pivot multiable DataTemplate
    Win10 UI入门 导航滑动条 求UWP工作
    UWP Control Toolkit Collections 求UWP工作
    Win10 UI入门 SliderRectangle
  • 原文地址:https://www.cnblogs.com/lpgit/p/9237409.html
Copyright © 2011-2022 走看看