# 廖雪峰的官方网站 python教材 1~4章# 格式控制符语法print('Hello, %s' % 'world')
print('hello, %s, you have %d dollars' % ('mickael', 1000))
print('hello, {0:s}, your grade {1:.1f}%'.format('xiaoming', 17.125))s1 = 72
s2 = 85
improve = (s2-s1)/s1 * 100
print('hello, {0:s}, your grade improved by {1:.1f}%'.format("xiaoming", improve));# 列表 listclassmate = ['xiaoming','xiaozhao','xiaohong']
print(classmate)print(len(classmate))print(classmate[1])classmate.insert(1,"Jack")
print(classmate)classmate.pop()
print(classmate)classmate.pop(1)
print(classmate)classmate[1] = "Sarah"
print(classmate)L = ['apple', 123, True]
print(L)# 判断age = 3
if age>= 18:print("adult")elif age >= 6:print("teenager")
else: print("kids")print("your age is", age)# 转换成 intbirth = input('birth: ')
birth = int(birth)
if birth < 2000:print("00qian")
else:print("00hou")# 循环sum = 0
for x in list(range(5)):sum = sum + x
print(sum)alphobets = ['a','b','c']
for char in alphobets:print(char)names = ['michael', 'bob', 'Tracy']
for name in names:print(name)sum = 0
i = 0
while(i<101):sum += ii += 1
print(sum)L = ['Bart', 'Lisa', 'Adam']
for name in L:print("hello, %s!" % name)# 字典 dictionaryd = {'Michael':95, 'Bob':75, 'Tracy':85}
d['Adam'] = 67
print(d['Adma'])# 函数def myabs(x):if not isinstance(x, (int, float)):raise TypeError('bad operand type')if x>=0:return xelse:return -xprint(myabs(111))# 函数返回元组import mathdef move(x, y, step, angle=0):nx = x + step * math.cos(angle)ny = y + step * math.sin(angle)return nx, ny# 分别赋给每个变量x, y = move(100,100,60,math.pi/6)
print(x,y)def quadratic(a,b,c):delta = b*b - 4*a*cx1 = (-b + math.sqrt(delta)) / (2 * a)x2 = (-b - math.sqrt(delta)) / (2 * a)return x1, x2print('quadratic(2, 3, 1) =', quadratic(2, 3, 1))
print('quadratic(1, 3, -4) =', quadratic(1, 3, -4))if quadratic(2, 3, 1) != (-0.5, -1.0):print('测试失败')
elif quadratic(1, 3, -4) != (1.0, -4.0):print('测试失败')
else:print('测试成功')#def power(x):# return x * x# 默认参数def power(x,n=2):s = 1while n > 0:n = n - 1s = s * xreturn sprint(power(5))
print(power(5,3))# 可变长度参数def clac(*numbers):sum = 0for n in numbers:sum = sum + n * nreturn sumprint(clac(1,2))
print(clac())# 递归:汉诺塔
# 参数n,表示初始时,3个柱子a、b、c中第1个柱子a上的盘子数量,
# 打印出把所有盘子从A借助B移动到C的方法
def move(n, a, b, c):if n == 1:print(a, '-->', c)else:move(n-1,a,c,b)print(a,'-->',c)move(n-1,b,a,c)returnmove(3,'A','B','C')

转载于:https://www.cnblogs.com/ZCplayground/p/8974159.html

python learning1.py相关推荐

  1. 解决 win10 pycurl安装出错 Command python setup.py egg_info failed with error code 10 编译安装包 安装万金油...

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/yexiaohhjk/article/d ...

  2. Python 运行 Python hello.py 出错,提示: File stdin , line 1

    写了一个hello.py,仅有一句,print 'hello world', 运行 Python hello.py 出错,提示: File "<stdin>" , li ...

  3. Python setup.py开发与安装

    本文翻译自:Python setup.py develop vs install Two options in setup.py develop and install are confusing m ...

  4. ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full comm

    目录 问题 解决方法 问题 Python3.7环境下安装PySide pip install PySide Collecting PySideUsing cached PySide-1.2.4.tar ...

  5. python pip 报错 Command “python setup.py egg_info“ failed with error code 1 解决方法

    在执行 pip3 install scrapy 时遇到错误: Command "python setup.py egg_info" failed with error code 1 ...

  6. python setup.py install 安装的包 卸载方法

    增加 –record 参数重新安装软件包,执行命令: python ./setup.py install --record install.txt 删除安装文件,执行命令: cat install.t ...

  7. python导入其他py文件-Python中py文件引用另一个py文件变量的方法

    最近自己初学Python,在编程是遇到一个问题就是,怎样在一个py文件中使用另一个py文件中变量,问题如下: demo1代码 import requests r = requests.get(&quo ...

  8. 使用Cython库包对python的py文件(源码)进行加密,把python的.py文件生成.so文件并调用

    文章目录: 1 准备环境 2 调用`Cython库包`把python的`.py`文件生成`.so`文件 2.1 写源码文件 2.2 调用源码接口 2.3 调用Cython库把`.py`源码生成`.so ...

  9. 如何在Jupyter notebook中运行python的.py文件,以及ipynb文件与py文件的相互转化

    文章目录: 1 Jupyter notebook中%开头的一些方法使用 1.1 运行python的py文件 1.2 加载本地文件 2 ipynb文件与py文件的相互转化 2.1 jupyter not ...

最新文章

  1. Android Studio Day03-1(Android studio 系统界面简介)
  2. 也谈贝叶斯分类(C#)版本
  3. Allocation Aizu - ALDS1_4_D
  4. [Qt教程] 第36篇 网络(六)UDP
  5. gradle项目搭建
  6. 重磅消息-Service Fabric 正式开源
  7. Mult-Nim博弈
  8. 内蒙古大学计算机组成原理实验,内蒙古大学计算机组成原理期末练习0
  9. mysql concat $_mysql concat 的诡异问题
  10. 2.12linux csf 防火墙 防止少量的ddos cc攻击
  11. 大清铜币到底是否稀缺,有收藏价值吗?
  12. 如何把Web缓存都充分利用上来?
  13. spark aggregate函数详解
  14. python IndentationError: unindent does not match any outer indentation level
  15. 推荐系列(四):矩阵分解|Matrix Factorization
  16. Openvino 模型文件部署推理
  17. 头部 CT 图像三维重建
  18. 计算机三级网络技术笔记
  19. php公众号被动回复,微信公众号被动消息回复原理解析
  20. 什么叫软件架构师(转)

热门文章

  1. 【Java从0到架构师】Linux 应用 - 软件包管理、软件安装
  2. 小程序入门学习09--云开发02
  3. 软件_git异常错误[博]
  4. 摆脱了Excel重复做表,换个工具轻松实现报表自动化,涨薪三倍
  5. 参与就有1000块,30W奖池你占一半 | 帆软开发者大赛招募
  6. Flex移动性能检查列表
  7. think php getfield,thinkPHP数据查询常用方法总结【select,find,getField,query】
  8. mysq命令行导出sql_mysql利用命令导出数据sql语句
  9. python十大必备知识_python学习必备知识汇总
  10. python图片马赛克_Python实现PS滤镜中马赛克效果示例