王二学习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. 《DSP using MATLAB》Problem 5.10

    代码: 第1小题: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Out ...

  2. css中的margin(外边框)、border(边框)、padding(填充)的区别

    Margin(外边距) - 清除边框外的区域,外边距是透明的. Border(边框) - 围绕在内边距和内容外的边框. Padding(内边距) - 清除内容周围的区域,内边距是透明的. Conten ...

  3. linux http配置

    yum install httpd 安装http服务器 启动http服务器即可访问 如果不行的话,试着执行命令 firewall-cmd –permanent –add-service=http(该命 ...

  4. 10 Rules of Highly Successful Project Management

    I commited the information below to report PDU of PMI. ^_^. In this paper, the author introduces his ...

  5. MySQL创建表,更新表,删除表,重命名表

    创建表 mysql> create table 表名( -> 列名 数据类型 是否为空 auto_increment, -> 列名 数据类型 是否为空... -> ... -& ...

  6. 如何让你的 KiCad 在缩放时不眩晕?

    如何让你的 KiCad 在缩放时不眩晕? 使用 KiCAD 第一感觉是打开速度非常快,而且 PCB 拉线也非常快,封装库又多. 但有一个问题,缩放时总给人一种眩晕,原来是因为鼠标自动跑到屏幕中间去了, ...

  7. kafka 的经典教程

    一.基本概念 介绍 Kafka是一个分布式的.可分区的.可复制的消息系统.它提供了普通消息系统的功能,但具有自己独特的设计. 这个独特的设计是什么样的呢? 首先让我们看几个基本的消息系统术语:Kafk ...

  8. [转]Jboss基础

    查看JBoss控制台JMX-Console //可以通过这个页面进行对 JBOSS 的各服务的配置和管理. http://localhost:8080/jmx-console/ 查看发布的WebSer ...

  9. 配置zabbix当内存剩余不足15%的时候触发报警

    zabbix默认的剩余内存报警:Average Lack of available memory on server {HOST.NAME}{Template OS Linux:vm.memory.s ...

  10. bootstrap-table设置表头宽度无效的解决方案

    bootstrap-table设置colmuns中某列的宽度无效时,需要给整个表设置css属性: .table { table-layout: fixed; }