王二学习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. PureComponent的作用及一些使用陷阱

    默认渲染行为的问题 在React Component的生命周期中,有一个shouldComponentUpdate方法.这个方法默认返回值是true. 这意味着就算没有改变组件的props或者stat ...

  2. 把oracle数据库恢复到某个时间点或者某个scn

    alter session set nls_date_format='yyyymmdd hh24:mi:ss'; select sysdate from dual; conn dbauser/1234 ...

  3. MySQL--InnoDB并发线程控制

    InnoDB并发线程控制 MySQL InnoDB存储引擎提供innodb_thread_concurrency来控制进入InnoDB 存储引擎的线程数,以限制InnoDB存储引擎层的并发量. 当in ...

  4. MySQL--数据库连接异常问题汇总

    ======================================================== Name or service not known 错误消息: [Warning] I ...

  5. Understanding Complex Event Processing (CEP)/ Streaming SQL Operators with WSO2 CEP (Siddhi)

    转自:https://iwringer.wordpress.com/2013/08/07/understanding-complex-event-processing-cep-operators-wi ...

  6. oracle-gi安装

    ############################################### 在cs6.5,cs7.2上安装grid11.2.0.1 和database11.2.0.1还是有问题 1 ...

  7. jQuery的ready()事件与js中的onload事件的区别

    出处:http://blog.csdn.net/yuanmei1986/article/details/50781453

  8. 阿里云 qW3xT.4 挖矿病毒问题

    查了一下.是个挖矿病毒,cpu 占用巨高 .杀了又有守护进程启动.网上有些杀死这个病毒的办法,大家可以试试.但是不确定能杀死. 建议直接重装系统. 然后,说说这货怎么传播的. 他通过redis .目前 ...

  9. VNC Viewer连接打开remote display的VMware虚拟机出现闪退

    只需修改vnc option里面Advanced-->expert-->ColourLevel的值为“rgb222” or “full”即可. 说明:rgb111--8 colours,r ...

  10. django ajax报错解决:You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set.

    Django版本号:1.11.15 django中ajax请求报错:You called this URL via POST, but the URL doesn't end in a slash a ...