王二学习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. java.lang.IllegalArgumentException: An invalid domain [.test.com] was specified for this cookie

    https://blog.csdn.net/cml_blog/article/details/52135115 当项目中使用单点登录功能时,通常会使用cookie进行信息的保存,这样就可以在多个子域名 ...

  2. Go Example--结构体

    package main import "fmt" //定义一个私有结构体 type person struct { name string age int } func main ...

  3. 从 Godaddy 转移域名到 Namesilo

    域名本来是在 Godaddy 上注册的,首付很便宜,但是续费时发现是个坑,续费一年是 102 元,再加上隐私保护 60元/年,总共一年需要 160 元,续费贵而且一点优惠也没. 对比下其他商家一年只要 ...

  4. 普林斯顿数学指南(第三卷) (Timothy Gowers 著)

    第V部分 定理与问题 V.1 ABC猜想 V.2 阿蒂亚-辛格指标定理 V.3 巴拿赫-塔尔斯基悖论 V.4 Birch-Swinnerton-Dyer 猜想 V.5 卡尔松定理 V.6 中心极限定理 ...

  5. shutdown和close

    close close 一个套接字的默认行为是把套接字标记为已关闭,然后立即返回到调用进程,该套接字描述符不能再由调用进程使用,也就是说它不能再作为read或write的第一个参数,然而TCP将尝试发 ...

  6. [转]JDK自带工具之问题排查场景示例

    最近看到了大量关于java性能调优.故障排查的文章,自己也写了一篇Java调优经验谈.接着此篇文章,其实一直打算写写一些常用调优工具以及它们的惯常用法的.后来在http://java-performa ...

  7. webpack 提取 manifest 文件

    当 webpack 生成 bundle 时, 它同时维护一个 manifest 文件.你可以在生成的 vendor bundle 中找到它.manifest 文件描述了哪些文件需要 webpack 加 ...

  8. TypeScript 之 NPM包的类型

    https://m.runoob.com/manual/gitbook/TypeScript/_book/doc/handbook/Typings%20for%20NPM%20Packages.htm ...

  9. 贪吃蛇(c语言实现)

    总结出以下几点: 1.需要多次被包含的头文件里不能定义全局变量,否则会报错“重定义” 2.char *strncpy(char *dest, const char *src, int n), 把src ...

  10. java中四种访问修饰符

    Java中的四种访问修饰符:public.protected.default(无修饰符,默认).private. 四种修饰符可修饰的成分(类.方法.成员变量)   public protected d ...