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

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

1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6
False or True or False and True and True orFalse
False or True or False or False
True

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

not True and True or False and True and True or False
False and True or False and True and True or False
False or False and True or False
False or False or False
False

2.求出下列逻辑语句的值,一定要自己分析

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

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 2 and 3 and 4 or 6 and 0 or 3
0 or 4 or 0 or 3
4

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

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

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

4 or 8 and not False and 8 or 9
4 or 8 and True and 8 or 9
4 or 8 or 9
4

3.下列结果是什么? (2>1这种是一体)

  1. 6 or 2 > 1

    6 or True
    6
  2. 3 or 2 > 1

    3 or True
    3
  3. 0 or 5 < 4

    0 or False
    False
  4. 5 < 4 or 3

    False or 3
    3
  5. 2 > 1 or 6

    True or 6
    True
  6. 3 and 2 > 1

    3 and True
    True
  7. 0 and 3 > 1

    0 and True
    0
  8. 2 > 1 and 3

    True and 3
    3
  9. 3 > 1 and 0

    True and 0
    0
  10. 3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2

    True and 2 or True and 3 and 4 or True
    2 or 4 or True
    2

4.简述ASCII、Unicode、utf-8编码

ASCII编码:不支持中文
Unicode:万国码,英文16位,中文32位
UTF-8:可变长编码,英文8位,欧洲文16位,亚洲文24位

5.简述位和字节的关系?

1 bytes = 8 bit

6.while循环语句基本结构?

while 空格 循环条件 冒号
缩进 循环体
else 空格 冒号
缩进 循环体

7.利用while语句写出猜大小的游戏:

设定一个理想数字比如:66,让用户输入数字,如果比66大,则显示猜测的结果大了;如果比66小,则显示猜测的结果小了;只有等于66,显示猜测结果正确,然后退出循环。

num = 66
while 1:
    num_input = int(input("请输入数字:"))
    if num_input > num :
        print("猜大了!")
    elif num_input < num :
        print("猜小了!")
    else :
        print("猜对了!")
        break

8.在7题的基础上进行升级:

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

num = 66
count = 3
while count:
    num_input = int(input("请输入数字:"))
    count -= 1
    if num_input > num :
        print("猜大了!")
    elif num_input < num :
        print("猜小了!")
    else :
        print("猜对了!")
        break
else :
    print("太笨了你....")

9.使用while循环输出 1 2 3 4 5 6 8 9 10

count = 0
while count < 10:
    count += 1
    if count == 7:
        continue
    else:
        print(count)

10.求1-100的所有数的和

count = 1
num = 0
while count<= 100:
    num +=count
    count+= 1
print(num)

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

count = 1
while count <= 100:
    if count % 2 == 1:
        print(count)
    count += 1

12.输出 1-100 内的所有偶数

count = 1
while count <= 100:
    if count % 2 == 0:
        print(count)
    count += 1

13.求1-2+3-4+5 ... 99的所有数的和

count = 1
num = 0
while count <= 99:
    if count % 2 == 1:
        num += count
    else:
        num -= count
    count += 1
print(num)

14.⽤户登陆(三次输错机会)且每次输错误时显示剩余错误次数(提示:使⽤字符串格式化)

count = 3
user = "zcy"
pwd = "122"
while count:
    user_input = input("请输入用户名:")
    pwd_input = input("请输入密码:")
    if user_input == str(user) and pwd_input == str(pwd):
        print("登陆成功")
        break
    else:
        count -= 1
        print("密码还剩%s次"%(count))

百万年薪python之路 -- 运算符及while的练习的更多相关文章

  1. 百万年薪python之路 -- JS基础介绍及数据类型

    JS代码的引入 方式1: <script> alert('兽人永不为奴!') </script> 方式2:外部文件引入 src属性值为js文件路径 <script src ...

  2. 百万年薪python之路 -- 面向对象之继承

    面向对象之继承 1.什么是面向对象的继承 继承(英语:inheritance)是面向对象软件技术当中的一个概念. 通俗易懂的理解是:子承父业,合法继承家产 专业的理解是:子类可以完全使用父类的方法和属 ...

  3. 百万年薪python之路 -- MySQL数据库之 MySQL行(记录)的操作(一)

    MySQL的行(记录)的操作(一) 1. 增(insert) insert into 表名 value((字段1,字段2...); # 只能增加一行记录 insert into 表名 values(字 ...

  4. 百万年薪python之路 -- 数据库初始

    一. 数据库初始 1. 为什么要有数据库? ​ 先来一个场景: ​ 假设现在你已经是某大型互联网公司的高级程序员,让你写一个火车票购票系统,来hold住十一期间全国的购票需求,你怎么写? 由于在同一时 ...

  5. 百万年薪python之路 -- 并发编程之 协程

    协程 一. 协程的引入 本节的主题是基于单线程来实现并发,即只用一个主线程(很明显可利用的cpu只有一个)情况下实现并发,为此我们需要先回顾下并发的本质:切换+保存状态 cpu正在运行一个任务,会在两 ...

  6. 百万年薪python之路 -- 函数的动态参数

    1.函数的动态参数 1.1 动态接收位置参数 在参数位置用*表示接受任意参数 def eat(*args): print('我想吃',args) eat('蒸羊羔','蒸熊掌','蒸鹿尾儿','烧花鸭 ...

  7. 百万年薪python之路 -- while循环

    day02 1.while循环 -- while关键字 while 空格 条件 冒号 缩进 循环体 while 5>4: print("Hello World!") 数字中非 ...

  8. 百万年薪python之路 -- 列表

    1.列表(list)-- list关键字 列表是python的基础数据类型之一,有顺序,可以切片方便取值,它是以[ ]括起来, 每个元素用' , '隔开而且可以存放各种数据类型(字符串,数字,布尔值, ...

  9. 百万年薪python之路 -- 前端CSS样式

    CSS样式 控制高度和宽度 width宽度 height高度 块级标签能设置高度和宽度,而内联标签不能设置高度和宽度,内联标签的高度宽度由标签内部的内容来决定. 示例: <!DOCTYPE ht ...

随机推荐

  1. Hadoop 文件系统命令行基础

    Hadoop 命令行最常用指令篇:  1.ls (list directory) Usage: hadoop fs -ls [R] Option: -R => 递归显示 2.mkdir (mak ...

  2. @Transient的用法和格式化页面展示的数据格式

    一.Hibernate中:@Transient用法 用法1:使用@Transient这个注解添加表中不存在字段.将这个注解添加到自定义字段的get方法上 用法2:将该注解添加到定义该字段的头部即可,例 ...

  3. css 实现图片灰度

    先看效果鼠标移入图片中摁下向左移动 图片由灰度变为原图   向右移动原图变灰度 ​ 代码如下:尚未做优化 <style> *{ margin:0; padding:0; } #img{ w ...

  4. scalikejdbc 学习笔记(5)

    常用增删改查操作: import scalikejdbc._ import scalikejdbc.config._ object CommonOperation { def main(args: A ...

  5. Vim 使用 DrawIt 画图

    简介 DrawIt 插件用来在 Vim 中进行简单的画图功能.可以方便地移动光标并画出横线.竖线.斜线.箭头和交叉字符,也带有实用的画图功能,轻松画带箭头的线.矩形及椭圆. 官方主页:https:// ...

  6. 访问http接口时返回502 Bad Getway什么原因怎么解决

    使用 httpclient 工具通过代理服务器请求第三方http 接口,多次返回 502 Bad Getway,少数返回正常. 502 Bad Getway是什么意思? 502 Bad Gateway ...

  7. 视频作品《springboot基础篇》上线了

    1.场景描述 第一个视频作品出炉了,<springboot基础篇>上线了,有需要的朋友可以直接点击链接观看.(如需购买,请通过本文链接购买) 2. 课程内容 课程地址:https://ed ...

  8. ubuntu14.04 安装tensorflow始末

    基于ubuntu14.04 干净的系统一步步遇到的坑记录下来: 怀着平静学习的心情,问题总的能解决的! 1. 首先看了下当前python版本 python --version Python 2.7.6 ...

  9. CentOS 7 的 systemctl 命令

    Centos 7.* 使用 Systemd 进行系统初始化,因此,Centos 7.* 中我们可以使用 systemctl 管理系统中的服务. systemctl 管理的服务均包含了一个以 .serv ...

  10. tp5中使用中间控制器代理路由,以避免创建过多的无用控制器方法

    在写项目的时候偶尔会加载一些不需要传递参数的静态视图,例如 class Index extends Common { public function index() { return $this-&g ...