王二学习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. mongodb备份与还原

    mongodb单机: 备份所有的库: mongodump --host 10.10.7.33:27019 --gzip --out /home/mongodb/0415_bf 备份指定的库: mong ...

  2. <--------------------------Java继承及抽象类------------------------------>

    1 继承的好处   关键词-->extends 1.1.继承的出现提高了代码的复用性,提高软件开发效率. 1.2.继承的出现让类与类之间产生了关系,提供了多态的前提. 2 继承的注意事项 *a: ...

  3. Modern Data Lake with Minio : Part 2

    转自: https://blog.minio.io/modern-data-lake-with-minio-part-2-f24fb5f82424 In the first part of this ...

  4. IE浏览器兼容问题

    文件兼容性用于定义让IE如何编译你的网页.此文件解释文件兼容性,如何指定你网站的文件兼容性模式以及如何判断一个网页该使用的文件模式. 为了帮助确保你的网页在所有未来的IE版本都有一致的外观,IE8引入 ...

  5. httpd

    http://httpd.apache.org/docs/2.2/logs.html httpd.conf文件 Configuration and logfile names: If the file ...

  6. Java基础语法 第2节 Java语言基本语法

    一.标识符和关键字 1.标识符 1)java中标识符用来为程序的白能量.常量.方法.类.接口和包名命名,标识符由字母.数字.下划线.美元符号组成,且第一个字符不能是数字: 2)标志符命名规则:见名知意 ...

  7. mqtt-jmeter

    mqtt-jmeter https://github.com/emqtt/mqtt-jmeter mqtt-jmeter MQTT JMeter Plugin, it's used for testi ...

  8. centos7 使用cgroup进行资源限制

    centos7中进行资源限制,使用的仍然是cgroup,只是配置接口使用的systemd. 下文将介绍如何使用systemd进行资源限制. Step1 编写unit文件 命令为my-demo.serv ...

  9. 自然语言处理hanlp的入门基础

      此文整理的基础是建立在hanlp较早版本的基础上的,虽然hanlp的最新1.7版本已经发布,但对于入门来说差别不大!分享一篇比较早的“旧文”给需要的朋友! 安装HanLP HanLP将数据与程序分 ...

  10. php Pthread 多线程基本介绍

    我们可以通过安装Pthread扩展来让PHP支持多线程.   线程,有时称为轻量级进程,是程序执行的最小单元.线程是进程中的一个实体,是被系统独立调度和分派的基本单位,线程自己不拥有系统资源,它与同属 ...