(1)

【Python学习】 之 Python3.x(小知识点汇集)_数据

(2)

【Python学习】 之 Python3.x(小知识点汇集)_python_02

(3)

【Python学习】 之 Python3.x(小知识点汇集)_柱状图_03

(4)

【Python学习】 之 Python3.x(小知识点汇集)_词频_04

(5)输入函数

【Python学习】 之 Python3.x(小知识点汇集)_python_05

(6)字符串操作

【Python学习】 之 Python3.x(小知识点汇集)_python_06

(7)表达式

【Python学习】 之 Python3.x(小知识点汇集)_数据_07

(8)分支语句

【Python学习】 之 Python3.x(小知识点汇集)_柱状图_08

(9)赋值语句

【Python学习】 之 Python3.x(小知识点汇集)_柱状图_09

(10)输出

【Python学习】 之 Python3.x(小知识点汇集)_词频_10

(11)循环语句

【Python学习】 之 Python3.x(小知识点汇集)_python_11

(12)数据类型总图

(13)数字类型

  ①整数类型

【Python学习】 之 Python3.x(小知识点汇集)_词频_12

  ②浮点数类型

【Python学习】 之 Python3.x(小知识点汇集)_词频_13


【Python学习】 之 Python3.x(小知识点汇集)_柱状图_14

  ③复数类型

【Python学习】 之 Python3.x(小知识点汇集)_词频_15

(14)数字类型转换

【Python学习】 之 Python3.x(小知识点汇集)_词频_16

(15)数字类型运算

【Python学习】 之 Python3.x(小知识点汇集)_词频_17

(16)字符串类型

【Python学习】 之 Python3.x(小知识点汇集)_词频_18


【Python学习】 之 Python3.x(小知识点汇集)_柱状图_19


【Python学习】 之 Python3.x(小知识点汇集)_python_20


【Python学习】 之 Python3.x(小知识点汇集)_柱状图_21


【Python学习】 之 Python3.x(小知识点汇集)_词频_22


【Python学习】 之 Python3.x(小知识点汇集)_柱状图_23


【Python学习】 之 Python3.x(小知识点汇集)_数据_24


【Python学习】 之 Python3.x(小知识点汇集)_数据_25


【Python学习】 之 Python3.x(小知识点汇集)_词频_26


【Python学习】 之 Python3.x(小知识点汇集)_数据_27


【Python学习】 之 Python3.x(小知识点汇集)_柱状图_28

(17)元组类型

【Python学习】 之 Python3.x(小知识点汇集)_柱状图_29


【Python学习】 之 Python3.x(小知识点汇集)_python_30


【Python学习】 之 Python3.x(小知识点汇集)_词频_31

(18)列表类型

【Python学习】 之 Python3.x(小知识点汇集)_词频_32


【Python学习】 之 Python3.x(小知识点汇集)_数据_33


【Python学习】 之 Python3.x(小知识点汇集)_词频_34


【Python学习】 之 Python3.x(小知识点汇集)_python_35


【Python学习】 之 Python3.x(小知识点汇集)_柱状图_36


【Python学习】 之 Python3.x(小知识点汇集)_词频_37

(19)math库使用

【Python学习】 之 Python3.x(小知识点汇集)_词频_38


【Python学习】 之 Python3.x(小知识点汇集)_词频_39

(20)random库使用

【Python学习】 之 Python3.x(小知识点汇集)_柱状图_40


【Python学习】 之 Python3.x(小知识点汇集)_柱状图_41


【Python学习】 之 Python3.x(小知识点汇集)_柱状图_42

(21)函数定义

【Python学习】 之 Python3.x(小知识点汇集)_数据_43


【Python学习】 之 Python3.x(小知识点汇集)_python_44


【Python学习】 之 Python3.x(小知识点汇集)_词频_45


【Python学习】 之 Python3.x(小知识点汇集)_python_46

(22)文件操作

【Python学习】 之 Python3.x(小知识点汇集)_数据_47


【Python学习】 之 Python3.x(小知识点汇集)_柱状图_48


【Python学习】 之 Python3.x(小知识点汇集)_python_49


【Python学习】 之 Python3.x(小知识点汇集)_python_50


【Python学习】 之 Python3.x(小知识点汇集)_柱状图_51


【Python学习】 之 Python3.x(小知识点汇集)_python_52


【Python学习】 之 Python3.x(小知识点汇集)_数据_53


【Python学习】 之 Python3.x(小知识点汇集)_python_54


【Python学习】 之 Python3.x(小知识点汇集)_python_55

(23)字典

收集统计文件中的单词并画柱状图

【Python学习】 之 Python3.x(小知识点汇集)_数据_56

# -*- coding: utf-8 -*-
"""
Created on Wed Jan 25 23:02:43 2017

@author: Donald
"""

import turtle

##全局变量##
#词频排列显示个数
count = 10
#单词频率数组-作为y轴数据
data = []
#单词数组-作为x轴数据
words = []
#y轴显示放大倍数-可以根据词频数量进行调节
yScale = 6
#x轴显示放大倍数-可以根据count数量进行调节
xScale = 30

################# Turtle Start ####################
#从点(x1,y1)到(x2,y2)绘制线段
def drawLine(t, x1, y1, x2, y2):
t.penup()
t.goto (x1, y1)
t.pendown()
t.goto (x2, y2)

# 在坐标(x,y)处写文字
def drawText(t, x, y, text):
t.penup()
t.goto (x, y)
t.pendown()
t.write(text)

def drawGraph(t):
#绘制x/y轴线
drawLine (t, 0, 0, 360, 0)
drawLine (t, 0, 300, 0, 0)

#x轴: 坐标及描述
for x in range(count):
x=x+1 #向右移一位,为了不画在原点上
drawText(t, x*xScale-4, -20, (words[x-1]))
drawText(t, x*xScale-4, data[x-1]*yScale+10, data[x-1])
drawBar(t)

#绘制一个柱体
def drawRectangle(t, x, y):
x = x*xScale
y = y*yScale#放大倍数显示
drawLine(t, x-5, 0, x-5, y)
drawLine(t, x-5, y, x+5, y)
drawLine(t, x+5, y, x+5, 0)
drawLine(t, x+5, 0, x-5, 0)

#绘制多个柱体
def drawBar(t):
for i in range(count):
drawRectangle(t, i+1, data[i])
################# Turtle End ####################


#对文本的每一行计算词频的函数
def processLine(line, wordCounts):
#用空格替换标点符号
line = replacePunctuations(line)
#从每一行获取每个词
words = line.split()
for word in words:
if word in wordCounts:
wordCounts[word] += 1
else:
wordCounts[word] = 1

#空格替换标点的函数
def replacePunctuations(line):
for ch in line:
if ch in "~@#$%^&*()_-+=<>?/,.:;{}[]|\'""":
line = line.replace(ch, " ")
return line

def main():
#用户输入一个文件名
filename = input("enter a filename:").strip()
infile = open(filename, "r")

#建立用于计算词频的空字典
wordCounts = {}
for line in infile:
processLine(line.lower(), wordCounts)

#从字典中获取数据对
pairs = list(wordCounts.items())

#列表中的数据对交换位置,数据对排序
items = [[x,y]for (y,x)in pairs]
items.sort()

#输出count个数词频结果
for i in range(len(items)-1, len(items)-count-1, -1):
print(items[i][1]+"\t"+str(items[i][0]))
data.append(items[i][0])
words.append(items[i][1])

infile.close()

#根据词频结果绘制柱状图
turtle.title('词频结果柱状图')
turtle.setup(900, 750, 0, 0)
t = turtle.Turtle()
t.hideturtle()
t.width(3)
drawGraph(t)

#调用main()函数
if __name__ == '__main__':
main()

(24)面向对象编程

# -*- coding: utf-8 -*-
"""
Created on Thu Jan 26 20:14:30 2017

@author: Donald
"""

from math import sin, cos, radians

class Projectile:
def __init__(self, angle, velocity, height):
#根据给定的发射角度、初始速度和位置创建一个投射体对象
self.xpos = 0.0
self.ypos = height
theta = radians(angle)
self.xvel = velocity * cos(theta)
self.yvel = velocity * sin(theta)

def update(self, time):
#更新投射体的状态
self.xpos = self.xpos + time * self.xvel
yvell = self.yvel - 9.8 * time
self.ypos = self.ypos + time * (self.yvel + yvell) / 2.0
self.yvel = yvell

def getY(self):
#返回投射体的角度
return self.ypos

def getX(self):
#返回投射体的距离
return
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 26 20:16:34 2017

@author: Donald
"""


from Projectile import *

def getInputs():
a = eval(input("Enter the launch angle (in degrees):"))
v = eval(input("Enter the initial velocity (in meters/sec):"))
h = eval(input("Enter the initial height (in meters):"))
t = eval(input("Enter the time interval: "))
return a,v,h,t

def main():
angle,vel,h0,time = getInputs()
shot = Projectile(angle,vel,h0)
while shot.getY() >=0:
shot.update(time)
print("\nDistance traveled:{0:0.1f}meters.".format(shot.getX()))

if __name__ == "__main__":
main()