王二学习python的笔记以及记录

学习内容

  1. python的历史:

    python2 源码不标准,混乱,重复代码太多,
    python3 统一 标准,去除重复代码。

  2. python 环境 

    编译型:一次性将所有程序编译成二进制文件。
    缺点:开发效率低,不能跨平台。
    优点:运行速度快。
    :C,C++等等。

    解释型:当程序执行时,一行一行的解释。
    优点:开发效率高,可以跨平台。
    缺点:运行速度慢。
    :python ,php,等等。

  3. 变量, 注释,用户交互
  4. 基础数据类型

代码区

如下是我自己的练习以及思考,方便起见,所有的思考都放在代码中,

1. 做一个猜年龄的游戏

age_of_boy = 18

guss = int(input('>>:'))
flag = True while flag ==True:
if guss > age_of_boy :
print('Too large, please try again')
guss = int(input('>>:'))
elif guss < age_of_boy :
print('Too small, please try again')
guss = int(input('>>:'))
else:
print('bingo, age of boy is: ',age_of_boy)
print('bingo, age of boy is: %d' %(age_of_boy))
flag = False
'''
心得:尝试连接非字符串值与字符串(导致 “TypeError: Can't convert 'int' object to str implicitly”)
print('bingo, age of boy is: ' + age_of_boy) 字符串与整型不能连接,直接相继打印即可 或者占空
'''

2. 屏幕显示从0-100

#
'''
count = 0 while count<=100:
print(count)
count = count + 1
'''
#
count = 0
flag = True while flag == True:
print(count)
count = count + 1
if count >100:
flag = False

3.从1加到100

count = 1
sum = 0 while count <= 100:
sum=sum + count
count = count + 1 print('1+2+3...100=',sum)

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

# 如何确定数字前的符号

#第一反应 奇数 偶数 分离

count = 0
sum = 0 while count < 100:
if count % 2 == 1 :
sum = sum + count
if count % 2 == 0 :
sum = sum - count
count = count + 1
print(sum,count) '''
# 网友答案
i = 0
sum1 = 0
sum2 = 0
while i<100:
i = i + 1
num1 = i%2
if num1 == 1:
sum1 = sum1 + i
else:
sum2 = sum2 + i
print(sum1-sum2) ''' # 网友的答案加到100,我的少定义一个变量,但是可以用一个if else

5.输出 1-100 内的所有偶数,奇数

#如何判断奇偶数    除2取余

print('输出1-100的奇数')
count = 0 while count < 100:
count = count + 1
if count % 2 == 1:
print(count) print('输出1-100的偶数')
count = 0
while count < 100:
count = count + 1
if count % 2 == 0:
print(count) # 心得:while if 记得写: 记得写空格, 规范代码

6. 显示1-5,90-100

'''
# 自己写
count = 1 while count <=100 :
if count <= 5 or count >= 90 :
print(count)
count = count + 1
'''
'''
#使用continue
count = 0 while count <= 100:
count = count + 1
if count > 5 and count < 90 :
continue
print(count)
'''
# break语句 练习 count = 0 while count <=100 :
count = count + 1
if count > 5 :
break
print(count) while count <=100 :
count = count + 1
if count < 90 :
continue
print(count)

7.用户登录(三次机会)

#涉及人机交互 跟猜年龄相似

'''
answer = 12306 count = 3 guess = int(input('请输入你的答案,剩余机会3次:')) while count >= 1:
count = count - 1
if guess == answer :
print('正在登陆,请稍后')
break
else:
if count == 0:
print('机会用完啦,明天再来吧')
break
print('密码错误,剩余次数:',count)
guess = int(input('请输入你的答案:'))
continue
'''
# 根据网友答案的反思 没有账号 account = 'NBA'
answer = 12306 count = 3 while count >= 1:
count = count - 1
acc = input('请输入账号')
if acc == account:
count = 3
while count >= 1:
count = count - 1
ans = int(input('请输入密码'))
if ans == answer :
print('正在登陆请稍后')
quit()
else :
print ('密码错误,剩余次数',count)
continue
else:
print('账号输入错误,剩余次数',count)
if count == 0:
print('机会用完啦,明天再来吧')
break
continue # break 只能跳出本次循环,quit()退出执行程序 '''
#网友答案
account="wangning"
password=123456 i = 0
while i<3:
i = i + 1
acc=input("please input your account:")
if acc == account:
i = 0
while i<3:
i = i + 1
passwd=int(input("please input your password:"))
if passwd == password:
quit()
else:
print("the password is error")
continue
else:
print("the account is error")
continue
'''

python之路——1的更多相关文章

  1. Python之路【第一篇】python基础

    一.python开发 1.开发: 1)高级语言:python .Java .PHP. C#  Go ruby  c++  ===>字节码 2)低级语言:c .汇编 2.语言之间的对比: 1)py ...

  2. Python之路

    Python学习之路 第一天   Python之路,Day1 - Python基础1介绍.基本语法.流程控制              第一天作业第二天   Python之路,Day2 - Pytho ...

  3. python之路 目录

    目录 python python_基础总结1 python由来 字符编码 注释 pyc文件 python变量 导入模块 获取用户输入 流程控制if while python 基础2 编码转换 pych ...

  4. Python之路【第十九篇】:爬虫

    Python之路[第十九篇]:爬虫   网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本.另外一些不常使用 ...

  5. Python之路【第十八篇】:Web框架们

    Python之路[第十八篇]:Web框架们   Python的WEB框架 Bottle Bottle是一个快速.简洁.轻量级的基于WSIG的微型Web框架,此框架只由一个 .py 文件,除了Pytho ...

  6. Python之路【第十七篇】:Django【进阶篇 】

    Python之路[第十七篇]:Django[进阶篇 ]   Model 到目前为止,当我们的程序涉及到数据库相关操作时,我们一般都会这么搞: 创建数据库,设计表结构和字段 使用 MySQLdb 来连接 ...

  7. Python之路【第十六篇】:Django【基础篇】

    Python之路[第十六篇]:Django[基础篇]   Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了O ...

  8. Python之路【第十五篇】:Web框架

    Python之路[第十五篇]:Web框架   Web框架本质 众所周知,对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. 1 2 3 4 5 6 ...

  9. Python之路【第九篇】:Python操作 RabbitMQ、Redis、Memcache、SQLAlchemy

    Python之路[第九篇]:Python操作 RabbitMQ.Redis.Memcache.SQLAlchemy   Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用 ...

  10. Python之路【第八篇】:堡垒机实例以及数据库操作

    Python之路[第八篇]:堡垒机实例以及数据库操作   堡垒机前戏 开发堡垒机之前,先来学习Python的paramiko模块,该模块机遇SSH用于连接远程服务器并执行相关操作 SSHClient ...

随机推荐

  1. hdu4998 Rotate 计算几何

    Noting is more interesting than rotation! Your little sister likes to rotate things. To put it easie ...

  2. javaweb防止表单重复提交

    参考孤傲苍狼 https://www.cnblogs.com/xdp-gacl/p/3859416.html 场景一:在网络延迟的情况下让用户有时间点击多次submit按钮导致表单重复提交 场景二:表 ...

  3. 【java编程】加载Resources配置文件的方法

    一.加载配置实现k-v //FILTER_PROPERTY_NAME=META-INF/abc.properties private void loadFilterConfig(Properties ...

  4. 【mybatis源码学习】调试mybatis的第一个程序

    [一].基础知识准备 mybatis-config.xml配置文件的结构 MyBatis配置文件中大标签configuration下子标签包括: configuration |--- properti ...

  5. struts2 中的数据访问servletAPI

    ActionContext包含其他数据对象,包括值栈     每次请求都会创建一个ActionContext对象 通过ActionContext访问数据 在action中读取  在jsp页面中读取 1 ...

  6. (惊艳)对象序列化和反序列--Hibernate的查询和新增极其相似

    Hibernate几个关键字持久化,ORM(关系对象映射)(数据库中关系称作是一张表) 应用在项目中,刘一从写的查询代码,每次都挂掉,想要弄出测试数据,自己想着把查询出来的复杂数据弄到文件里自己要是去 ...

  7. malloc,calloc,alloca和free函数

    void *malloc(size_t size)因为返回类型为空,所以可以赋值到任何类型指针,其分配的空间大小为size,返回新分配内存地址的起始处的指针,其所分配的内存未经初始化,若分配失败返回N ...

  8. HTTP redirect 重定向到 HTTPS

    最近帮一个顾客做网站,  需要HTTPS. 之前接触的SSL certificate直接上传到plesk 上面勾选重定向即可. 在此先吐槽下godaddy 服务贵功能还少. 用代码从HTTP来重定向到 ...

  9. CloudStack学习-2

    环境准备 这次实验主要是CloudStack结合glusterfs. 两台宿主机,做gluster复制卷 VmWare添加一台和agent1配置一样的机器 系统版本:centos6.6 x86_64 ...

  10. TypeScript 之 声明文件的结构

    https://www.tslang.cn/docs/handbook/declaration-files/library-structures.html 模块化库 一些库只能工作在模块加载器的环境下 ...