练习

  1. 判断下列逻辑语句的结果,一定要自己先分析

    1)1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6

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

    答案:

    1)True

    2)_False

    验证:

    print(1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6)
    print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6)
  2. 求出下列逻辑语句的值,一定要自己分析

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

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

    3)1 and 0 or 8 and 9 and 5 or 2

    4)4 or 8 and not False and 8 or 9

    答案:

    1)8

    2)4

    3)5

    4)4

    验证:

    print(8 or 3 and 4 or 2 and 0 or 9 and 7)
    print(0 or 2 and 3 and 4 or 6 and 0 or 3)
    print(1 and 0 or 8 and 9 and 5 or 2)
    print(4 or 8 and not False and 8 or 9)
  3. 下列结果是什么? (2>1这种是一体)

    1)6 or 2 > 1
    2)3 or 2 > 1
    3)0 or 5 < 4
    4)5 < 4 or 3
    5)2 > 1 or 6
    6)3 and 2 > 1
    7)0 and 3 > 1
    8)2 > 1 and 3
    9)3 > 1 and 0
    10)3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2

    答案:

    1)6

    2)3

    3)False

    4)3

    5)True

    6)True

    7)0

    8)3

    9)0

    10)2

    验证:

    print(6 or 2 > 1)
    print(3 or 2 > 1)
    print(0 or 5 < 4)
    print(5 < 4 or 3)
    print(2 > 1 or 6)
    print(3 and 2 > 1)
    print(0 and 3 > 1)
    print(2 > 1 and 3)
    print(3 > 1 and 0)
    print(3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2)
  4. 简述ASCII、Unicode、utf-8编码

    # ASCII:美国人发明的,不支持中文 英文8位1字节
    # Unicode:万国码 英文16位2个字节 中文32位4个字节
    # utf-8:(可变编码)英文8位1个字节 欧洲16位2个字节 亚洲24位3个字节
  5. 简述位和字节的关系?

    # 1字节=8位
    # 1Bytes=1bits
  6. while循环语句基本结构?

    while 空格 条件 冒号
    缩进 循环体
    while 空格 条件 冒号
    缩进 循环体
    else 冒号
    缩进 结果
  7. 利用while语句写出猜大小的游戏:

    设定一个理想数字比如:66,让用户输入数字,

    如果比66大,则显示猜测的结果大了;

    如果比66小,则显示猜测的结果小了;

    只有等于66,显示猜测结果正确,然后退出循环。

    代码:

    num=66
    while True:
    num1=int(input("请输入猜测数字"))
    if num1==num:
    print("猜测正确!")
    break
    elif num1>num:
    print("猜大了")
    else:
    print("猜小了")
  8. 在7题的基础上进行升级:

    给用户三次猜测机会,如果三次之内猜测对了,则显示猜测正确,退出循环,

    如果三次之内没有猜测正确,则自动退出循环,并显示‘太笨了你....’。

    代码:

    num=66
    n=3
    while n:
    num1=int(input("请输入猜测数字"))
    n-=1
    if num1==num:
    print("猜测正确!")
    break
    elif num1>num:
    print("猜大了")
    else:
    print("猜小了")
    else:
    print("你太笨了",end="")
  9. 使用while循环输出 1 2 3 4 5 6 8 9 10

    num=0
    while num<10:
    num += 1
    if num==7:
    continue
    print(num)
  10. 求1-100的所有数的和

    答案:5050

    num=0
    n=1
    while n<=100:
    num=num+n
    n=n+1
    print(num)
```python

```
  1. 输出 1-100 内的所有奇数

    n=1
    while n<100:
    print(n)
    n=n+2
  2. 输出 1-100 内的所有偶数

    n=0
    while n<100:
    n=n+2
    print(n)
  3. 求1-2+3-4+5 ... 99的所有数的和

    答案:50

    代码:

    num=0
    n=1
    while n<100:
    if n%2==0:
    num=num-n
    else:
    num=num+n
    n=n+1
    print(num)
  4. ⽤户登陆(三次输错机会)且每次输错误时显示剩余错误次数(提示:使⽤字符串格式化)

    name="alex"
    psd="admin123" n=3
    while n:
    n=n-1
    num1=input("请输入账号:")
    psd1=input("请输入密码:")
    if num1==name and psd==psd1:
    print("成功登陆!")
    break
    else:
    print("账号或密码错误,你还剩下%d次机会"%(n))
  5. 求1-3+5-7+9-...99的结果

    sum = 0
    flag = 1
    num = 1
    while num < 100:
    sum += num * flag
    num = num + 2
    flag = flag * -1
    print(sum)

最新文章

  1. 算法与数据结构(八) AOV网的关键路径
  2. 修复Linux Mint损坏的依赖
  3. PHP计算两个时间段是否有交集(边界重叠不算)
  4. Cassandra 配制 cassandra.yaml
  5. Ubuntu/linux 有关权限修改的命令
  6. 加州大学伯克利分校Stat2.2x Probability 概率初步学习笔记: Midterm
  7. mysql安装过程中出现错误ERROR 1820 (HY000): You must SET PASSWORD before executing this statement解决
  8. Linux下如何查找可执行文件
  9. 网站后台登录aspcms 提示错误号:-2147467259,错误描述:操作必须使用一个可更新的查询。sql=update AspCms_Content set TimeStatus=0 where TimeStatus=1 and Timeing &lt;= 解决方法。
  10. Mentor PADS 9.5下载安装及破解指南
  11. Struts2 + uploadify 多文件上传完整的例子!
  12. hdu1030
  13. 语音识别完成诗句的查询功能,iOS AVSpeechSynthesis语音输出结果的诗歌APP
  14. 利用Node的chokidar 监听文件改变的文件。
  15. MySQL Group Relication 部署环境入门篇
  16. bootstap初识之css
  17. Java 线程池的原理及实现
  18. 笔记 : win8系统中的VM虚拟机的Ubuntu搭建samba服务
  19. Apache按天截断日志工具,无法生成访问日志
  20. 使用C++ Builder XE5获取Sensor值之Light Sensor

热门文章

  1. python从入门到实践 第二章
  2. js dom 添加类
  3. (60) 结构体指针、结构体变量嵌套、结构体指针嵌套、函数指针、数组指针、指针数组、typedef 综合运用
  4. 根据linux自带的JDK,配置JAVA_HOME目录
  5. sqli-labs(27a)
  6. 关于同时可用git命令clone和TortoiseGit拉取代码不需要密码
  7. Ubuntu 12.04输入密码登陆后又跳回到登录界面
  8. Spring MVC 同一个方法同时返回view或json
  9. java内存分布详解
  10. visudo编辑sudoers