Python练习_Python初识_day2
题目
1.作业
1、判断下列逻辑语句的True,False.
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 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)、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 4、while循环语句基本结构? 5、利用if语句写出猜大小的游戏:
设定一个理想数字比如:66,让用户输入数字,如果比66大,则显示猜测的结果大了;如果比66小,则显示猜测的结果小了;只有等于66,显示猜测结果正确,然后退出循环。 6、在5题的基础上进行升级:
给用户三次猜测机会,如果三次之内猜测对了,则显示猜测正确,退出循环,如果三次之内没有猜测正确,则自动退出循环,并显示‘太笨了你....’。 7、使用while循环输出 1 2 3 4 5 6 8 9 10 8、求1-100的所有数的和 9、输出 1-100 内的所有奇数(两种方法) 10、输出 1-100 内的所有偶数(两种方法) 11、求1-2+3-4+5 ... 99的所有数的和 12、⽤户登陆(三次输错机会)且每次输错误时显示剩余错误次数(提示:使⽤字符串格式化) 13、简述ASCII、Unicode、utf-8编码关系? 14、简述位和字节的关系? 15、“⽼男孩”使⽤UTF-8编码占⽤⼏个字节?使⽤GBK编码占⼏个字节?
2.
2.默写
1. Bit,Bytes,KB,MB,GB,TB之间的转换关系。
2. Unicode,utf-8,GBK,每个编码英文,中文,分别用几个字节表示。
答案
1、判断下列逻辑语句的True,False.
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
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
1)8
2)4
3、下列结果是什么?
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
4、while循环语句基本结构?
while 条件:
循环体
5、利用if语句写出猜大小的游戏:
设定一个理想数字比如:66,让用户输入数字,如果比66大,则显示猜测的结果大了;如果比66小,则显示猜测的结果小了;只有等于66,显示猜测结果正确,然后退出循环。
f = 66
while 1:
num = int(input('请输入一个数字:'))
if f == num:
print('猜测正确')
break
elif f > num:
print('小了')
else:
print('大了')
6、在5题的基础上进行升级:
给用户三次猜测机会,如果三次之内猜测对了,则显示猜测正确,退出循环,如果三次之内没有猜测正确,则自动退出循环,并显示‘太笨了你....’。
f = 66
count = 0
while 1:
if count == 3:
print('太笨了你')
break
num = int(input('请输入一个数字:'))
if f == num:
print('猜测正确')
break
elif f > num:
print('小了')
count += 1
else:
print('大了')
count += 1
7、使用while循环输出 1 2 3 4 5 6 8 9 10
count = 0
while count < 10:
count += 1
if count == 7:
continue
print(count)
8、求1-100的所有数的和
while 1:
sum = 0
for i in range(101):
sum += i
print(sum)
break
9、输出 1-100 内的所有奇数(两种方法)
方法一:
for i in range(1,101, 2):
print(i)
方法二:
count = 1
while count < 101:
if count % 2 == 1:
print(count)
count += 2
else:
count += 2
10、输出 1-100 内的所有偶数(两种方法)
方法一:
for i in range(2,101, 2):
print(i)
方法二:
count = 2
while count < 101:
if count % 2 == 0:
print(count)
count += 2
else:
count += 2
11、求1-2+3-4+5 ... 99的所有数的和
count = 1
sum = 0
while count < 100:
sum += (-1)**(count-1) * count
count += 1
print(sum)
12、⽤户登陆(三次输错机会)且每次输错误时显示剩余错误次数(提示:使⽤字符串格式化)
i = 3
username = "yangxiaoer"
password = ""
while i>=0:
name = input("请输入你的用户名:")
if name == username:
passwd = input("请输入你的密码:")
if passwd == password:
print("登录成功。请稍后")
print('''
username: %s
password: %s
'''%(username,password))
break
else:
print("你的密码错误 请重新输入")
print("你还有%s次机会" % (i-1))
if i == 0:
print('您的机会已经用完,结束本次操作')
break
continue
else:
print("你的用户名错误!请重新输入")
print("你还有%s次机会"%(i-1))
i -= 1 username = "yangxiaoer"
password = ""
i = 3
while i > 0:
zh = input("请输入你的账号:")
i -= 1
if zh == username:
mm = input("请输入你的密码:")
if mm == password:
print("验证成功.正在登陆......")
print('''恭喜你登陆成功!
欢迎用户进入
用户名 :%s
密码 :%s
'''%(zh,mm))
break
else:
if i == 0:
print("你的机会已经没了!game over 下次见!")
answer = input('再试试?Y or N')
if answer == 'Y':
i = 3
print("密码错误,请重新输入")
print("你还有"+str(i)+"次机会")
else:
print("请输入正确的用户名!")
if i == 0:
print("你的机会已经没了!")
answer = input('再试试?Y or N')
if answer == 'Y':
i = 3
print("你还有" + str(i) + "次机会")
else:
print('你TM要不要脸')
13、简述ASCII、Unicode、utf-8编码关系?
ASCII码:
英文:8位
Unicode:
英文:32位
中文:32位
UTF-8:
英文:8位
欧洲文字:16位
中文:24位
14、简述位和字节的关系?
8位 == 1个字节
15、“⽼男孩”使⽤UTF-8编码占⽤⼏个字节?使⽤GBK编码占⼏个字节?
UTF-8:9个字节
GBK:6个字节
默写
1.Bit,Bytes,KB,MB,GB,TB之间的转换关系。
8 bit = 1Bytes
1024 Bytes = 1KB
1024 KB = 1MB
1024 MB = 1GB
1024 GB = 1TB
2.Unicode,utf-8,GBK,每个编码英文,中文,分别用几个字节表示。
Unicode:
起初:英 16位
中16位
优化:全为32位 utf-8:
英:8位
欧:16位
中:24位 GBK:
英:8位
中:16位
-
Python练习_Python初识_day2的更多相关文章
- Python练习_Python初识_day1
题目 1.作业 1.简述变量命名规范 2.name = input(“>>>”) name变量是什么数据类型? 3.if条件语句的基本结构? 4.用print打印出下面内容: ⽂能提 ...
- python开发_python关键字
python3.3.2中的关键字如下: The following identifiers are used as reserved words, or keywords of the languag ...
- 孤荷凌寒自学python第二十一天初识python的类
孤荷凌寒自学python第二十一天初识python的类 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 类是面向对象的编程语言非常重要的概念. 编程语言的进化史中从顺序编程到结构化编程,最后才 ...
- Python 入门 之 初识面向对象
Python 入门 之 初识面向对象 1.初识面向对象编程 (核心--对象) (1)观察以下代码: # 面向过程编程 s = "alexdsb" count = 0 for i i ...
- Python 字符串_python 字符串截取_python 字符串替换_python 字符串连接
Python 字符串_python 字符串截取_python 字符串替换_python 字符串连接 字符串是Python中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符 ...
- python函数-函数初识
python函数-函数初识 1.函数的定义 语法 def 函数名(参数1,参数2,参数3,...): '''注释''' 函数体 return 返回的值 2.函数的使用原则---先定义后调用 #定义阶段 ...
- 01----python入门----python安装与初识
----python入门----python安装与初识 python是一门编程语言,作为学习python的开始,需要事先搞明白:编程的目的是什么?什么是编程语言?什么是编程? 这是一个很好的开头!但是 ...
- python之路——初识函数
阅读目录 为什么要用函数 函数的定义与调用 函数的返回值 函数的参数 本章小结 返回顶部 为什么要用函数 现在python届发生了一个大事件,len方法突然不能直接用了... 然后现在有一个需求,让你 ...
- python之路--初识面向对象
一 . 初识面向对象 面向过程: 一切以事务的发展流程为中心. 面向对象: 一切以对象为中心. 一切皆为对象. 具体的某一个事务就是对象 打比方: 大象进冰箱 步骤: 第一步, 开门, 第二步, 装大 ...
随机推荐
- Android仿微信底部选项卡
第一步 添加依赖 dependencies { compile 'com.yinglan.alphatabs:library:1.0.5' } 第二步 布局使用 <?xml version=&q ...
- 解压命令unzip常用方法汇总
解压命令unzip常用方法汇总: 1.把文件解压到当前目录下 1 unzip pythontab.com.zip 2.如果要把文件解压到指定的目录下,需要用到-d参数. 1 unzip -d ./tm ...
- java代码规范好文推荐
近期发现一遍好文章 看过之后觉得自己代码存在太多的问题 特此记录一下 和大家一起分享 https://xwjie.github.io/rule/
- asp.net怎样实现批量下载文件(非打包形式下载)
问题: 我想实现的是一个一个的下载. 比如我有一个文件列表.通过checkbox选择.通过单击下载按钮下载选中文件. 百度到都是用打包形式实现批量下载. 这是我自己写的代码,但是点击下载后只能下载一个 ...
- 新手pyhoner的指定内容读取和写入的思路
在linux上,很容易碰到操作文件的内容,读取指定信息的情况,或者要求在指定内容中追加内容,其实两个flag标识符就能解决. 先上个图: 执行while flag==0即可: while flag== ...
- linux上安装pycharm
百度搜索pycharm 然后打开pycharm的官网 然后在官网首页点击down,下载linux版pycharm 上传到linux服务器.解压 然后再打开bin目录 执行:sh ./pycharm.s ...
- NVIDIA显卡电源不足
NVIDIA显卡 Ubuntu16.04安装驱动后出现问题:Unable to determine the device handle for GPUXXX 安装NVIDIA驱动后输入:nvidia- ...
- C#API解决自定义请求头下的跨域问题
解决方法一: public class CrosHandler : DelegatingHandler { private const string Origin = "Origin&quo ...
- laydate年份选择,关闭底框,点击指定年份就选择然后关闭控件,翻页不选择也不关闭控件
如下图,翻页不选择也不关闭.点击指定年份时再选择和关闭控件 代码如下 // 默认没有选择,把判断赋值当前时间 var iYearCode = parseInt(new Date().getFullYe ...
- jquery实现微博输入和发布
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...