《python程序设计》(mooc)

目录

pass

一、第0章

  • 课程基本情况
  • 课程内容导学

二、第1周:python基本语法元素(感性认识)

  • 程序设计基本方法
  • 计算机与程序设计
  • 编译和解释

计算机执行源程序的两种方式:编译和解释
源代码——>目标代码
静态语言和脚本语言

  • 编程的基本编写方法(IPO)

  • 计算机编程

  • 单元小结
    在这里插入图片描述

  • python开发环境配置

  • Python语言概述

  • Python基本开发环境IDLE

  • Python程序编写和运行

两种编程方式:交互式和文件性

  • python高级开发环境VSCode

  • 单元小结

  • 实例一:温度转换

  • “温度转换”问题分析

  • “温度转换”实例编写

  • “温度转换”举一反三

  • python程序语法元素分析

  • 程序的格式框架

  • 命名与保留字

  • 数据类型
    在这里插入图片描述

  • 语句与函数

  • 输入输出

eval():去掉参数最外层引号并执行余下语句函数

  • “温度转换”代码分析
  • 单元小结
    在这里插入图片描述

三、第2周:python基本图形绘制

  • 深入理解python语言
  • 计算机技术的演进

在这里插入图片描述

  • 编程语言的多样初心

这里是引用

  • python语言的特点

  • “超级语言的诞生”

  • 实例2:python蟒蛇绘制

import turtle as tt
tt.setup(650,350,200,200)
tt.penup()
tt.fd(-250)
tt.pendown()
tt.pensize(25)
tt.pencolor("red")
tt.seth(-40)
for i in range(4):
    tt.circle(40,80)
    tt.circle(-40,80)
tt.circle(40,80/2)
tt.fd(40)
tt.circle(16,180)
tt.fd(40*2/3)
tt.done
  • 模块1:turtle库的使用
  • turtle库的基本介绍

标准库

  • turtle绘图窗体布局

turtle.setup(width,height,startx,stary)
turtle.setup(800,400,0,0) #大小单位为像素,后两个参数设置位置,可选

  • turtle空间坐标体系

  • turtle角度坐标体系

  • RGB色彩体系

  • turtle程序语法元素分析

  • 库引用与import

  • turtle画笔控制函数

  • turtle运动控制函数

  • turtle方向控制函数

  • 循环语句与range()函数

  • 绘制小猪佩奇:

# coding:utf-8
import turtle as t
# 绘制小猪佩奇
# =======================================
 
t.pensize(4)
t.hideturtle()
t.colormode(255)
t.color((255, 155, 192), "pink")
t.setup(840, 500)
t.speed(10)
 
# 鼻子
t.pu()
t.goto(-100,100)
t.pd()
t.seth(-30)
t.begin_fill()
a = 0.4
for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a+0.08
        t.lt(3)  # 向左转3度
        t.fd(a)  # 向前走a的步长
    else:
        a = a-0.08
        t.lt(3)
        t.fd(a)
        t.end_fill()
 
t.pu()
t.seth(90)
t.fd(25)
t.seth(0)
t.fd(10)
t.pd()
t.pencolor(255, 155, 192)
t.seth(10)
t.begin_fill()
t.circle(5)
t.color(160, 82, 45)
t.end_fill()
 
t.pu()
t.seth(0)
t.fd(20)
t.pd()
t.pencolor(255, 155, 192)
t.seth(10)
t.begin_fill()
t.circle(5)
t.color(160, 82, 45)
t.end_fill()
 
# 头
t.color((255, 155, 192), "pink")
t.pu()
t.seth(90)
t.fd(41)
t.seth(0)
t.fd(0)
t.pd()
t.begin_fill()
t.seth(180)
t.circle(300, -30)
t.circle(100, -60)
t.circle(80, -100)
t.circle(150, -20)
t.circle(60, -95)
t.seth(161)
t.circle(-300, 15)
t.pu()
t.goto(-100, 100)
t.pd()
t.seth(-30)
a = 0.4
for i in range(60):
    if 0 <= i < 30 or 60 <= i <90:
        a = a+0.08
        t.lt(3)  # 向左转3度
        t.fd(a)  # 向前走a的步长
    else:
        a = a-0.08
        t.lt(3)
        t.fd(a)
        t.end_fill()
 
# 耳朵
t.color((255, 155, 192), "pink")
t.pu()
t.seth(90)
t.fd(-7)
t.seth(0)
t.fd(70)
t.pd()
t.begin_fill()
t.seth(100)
t.circle(-50, 50)
t.circle(-10, 120)
t.circle(-50, 54)
t.end_fill()
 
t.pu()
t.seth(90)
t.fd(-12)
t.seth(0)
t.fd(30)
t.pd()
t.begin_fill()
t.seth(100)
t.circle(-50, 50)
t.circle(-10, 120)
t.circle(-50, 56)
t.end_fill()
 
#眼睛
t.color((255, 155, 192), "white")
t.pu()
t.seth(90)
t.fd(-20)
t.seth(0)
t.fd(-95)
t.pd()
t.begin_fill()
t.circle(15)
t.end_fill()
 
t.color("black")
t.pu()
t.seth(90)
t.fd(12)
t.seth(0)
t.fd(-3)
t.pd()
t.begin_fill()
t.circle(3)
t.end_fill()
 
t.color((255, 155, 192), "white")
t.pu()
t.seth(90)
t.fd(-25)
t.seth(0)
t.fd(40)
t.pd()
t.begin_fill()
t.circle(15)
t.end_fill()
 
t.color("black")
t.pu()
t.seth(90)
t.fd(12)
t.seth(0)
t.fd(-3)
t.pd()
t.begin_fill()
t.circle(3)
t.end_fill()
 
# 腮
t.color((255, 155, 192))
t.pu()
t.seth(90)
t.fd(-95)
t.seth(0)
t.fd(65)
t.pd()
t.begin_fill()
t.circle(30)
t.end_fill()
 
# 嘴
t.color(239, 69, 19)
t.pu()
t.seth(90)
t.fd(15)
t.seth(0)
t.fd(-100)
t.pd()
t.seth(-80)
t.circle(30, 40)
t.circle(40, 80)
 
# 身体
t.color("red", (255, 99, 71))
t.pu()
t.seth(90)
t.fd(-20)
t.seth(0)
t.fd(-78)
t.pd()
t.begin_fill()
t.seth(-130)
t.circle(100,10)
t.circle(300,30)
t.seth(0)
t.fd(230)
t.seth(90)
t.circle(300,30)
t.circle(100,3)
t.color((255,155,192),(255,100,100))
t.seth(-135)
t.circle(-80,63)
t.circle(-150,24)
t.end_fill()
 
# 手
t.color((255,155,192))
t.pu()
t.seth(90)
t.fd(-40)
t.seth(0)
t.fd(-27)
t.pd()
t.seth(-160)
t.circle(300,15)
t.pu()
t.seth(90)
t.fd(15)
t.seth(0)
t.fd(0)
t.pd()
t.seth(-10)
t.circle(-20,90)
 
t.pu()
t.seth(90)
t.fd(30)
t.seth(0)
t.fd(237)
t.pd()
t.seth(-20)
t.circle(-300,15)
t.pu()
t.seth(90)
t.fd(20)
t.seth(0)
t.fd(0)
t.pd()
t.seth(-170)
t.circle(20,90)
 
# 脚
t.pensize(10)
t.color((240,128,128))
t.pu()
t.seth(90)
t.fd(-75)
t.seth(0)
t.fd(-180)
t.pd()
t.seth(-90)
t.fd(40)
t.seth(-180)
t.color("black")
t.pensize(15)
t.fd(20)
 
t.pensize(10)
t.color((240, 128, 128))
t.pu()
t.seth(90)
t.fd(40)
t.seth(0)
t.fd(90)
t.pd()
t.seth(-90)
t.fd(40)
t.seth(-180)
t.color("black")
t.pensize(15)
t.fd(20)
 
# 尾巴
t.pensize(4)
t.color((255, 155, 192))
t.pu()
t.seth(90)
t.fd(70)
t.seth(0)
t.fd(95)
t.pd()
t.seth(0)
t.circle(70, 20)
t.circle(10, 330)
t.circle(70, 30)
t.done()
  • 绘制玫瑰花:
import turtle
 
# 设置初始位置
turtle.penup()
turtle.left(90)
turtle.fd(200)
turtle.pendown()
turtle.right(90)
 
# 花蕊
turtle.fillcolor("red")
turtle.begin_fill()
turtle.circle(10,180)
turtle.circle(25,110)
turtle.left(50)
turtle.circle(60,45)
turtle.circle(20,170)
turtle.right(24)
turtle.fd(30)
turtle.left(10)
turtle.circle(30,110)
turtle.fd(20)
turtle.left(40)
turtle.circle(90,70)
turtle.circle(30,150)
turtle.right(30)
turtle.fd(15)
turtle.circle(80,90)
turtle.left(15)
turtle.fd(45)
turtle.right(165)
turtle.fd(20)
turtle.left(155)
turtle.circle(150,80)
turtle.left(50)
turtle.circle(150,90)
turtle.end_fill()
 
# 花瓣1
turtle.left(150)
turtle.circle(-90,70)
turtle.left(20)
turtle.circle(75,105)
turtle.setheading(60)
turtle.circle(80,98)
turtle.circle(-90,40)
 
# 花瓣2
turtle.left(180)
turtle.circle(90,40)
turtle.circle(-80,98)
turtle.setheading(-83)
 
# 叶子1
turtle.fd(30)
turtle.left(90)
turtle.fd(25)
turtle.left(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(-80,90)
turtle.right(90)
turtle.circle(-80,90)
turtle.end_fill()
 
turtle.right(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(85)
turtle.left(90)
turtle.fd(80)
 
# 叶子2
turtle.right(90)
turtle.right(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(80,90)
turtle.left(90)
turtle.circle(80,90)
turtle.end_fill()
 
turtle.left(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(60)
turtle.right(90)
turtle.circle(200,60)

四、第3周:基本数据类型

  • 数据类型及操作
  • 整数类型

pow(x,y)函数,计算x的y次方
四种进制的表达形式

  • 浮点数类型

浮点数间运算存在不确定尾数,不是bug。
可以使用round(x,d)函数辅助

  • 复数类型

x.real获得实部
x.imag获得虚部

  • 数值运算操作符

abs()
divmod(x,y) 商余
pow(x,y[,z]) 幂余

  • 数值运算函数
  • 实例3:天天向上的力量
  • 字符串类型及操作
  • 字符串类型的表示
  • 字符串操作符
  • 字符串处理函数

hen(),oct(),chr(),ord()

  • *字符串处理方法

str.lower(),srt.upper(),str.split(),str.count(),str.replace(),str.center(),str.strip(),str.jion()

  • *字符串类型的格式化

format()

  • 模块2:time库的使用
  • time库基本介绍

标准函数
包含三类函数:
时间获取:time(),ctime(),gmtime()
时间格式化:strftime()
程序计时:perf_counter(),sleep()

  • 时间获取
  • 时间格式化
  • 程序计时应用
  • 实例4:文本进度条
#简单开始
import time
scale = 10
print("-------执行开始------")
for i in range(scale+1):
    a = '*' * i
    b = '.' * (scale-i)
    c = (i/scale)*100
    print("{:3.0f}%[{}->{}]".format(c,a,b))
    time.sleep(0.1)
print("-------执行结束--------")

#完整代码
#TextProBarV3.py
 import time
 scale = 50
 print("执行开始".center(scale//2, "-"))
 start = time.perf_counter()
 for i in range(scale+1):
     a = '*' * i
     b = '.' * (scale - i)
     c = (i/scale)*100
     dur = time.perf_counter() - start
     print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur),end='')
     time.sleep(0.1)
print("\n"+"执行结束".center(scale//2,'-'))

五、第4周:程序的控制结构

  • 程序分支结构
  • 单分支结构
  • 二分支结构
  • 多分支结构
  • 条件判断及组合
  • 程序的异常处理

这里是引用

  • 实例5:身体质量指数BMI
  • 程序的循环结构
  • 遍历循环
  • 无限循环
  • 循环控制保留字
  • 循环的高级用法

这里是引用

  • 模块3:random库的使用
  • random库的基本介绍
  • 基本随机函数

seed(),random()

  • 扩展随机函数

randint(),getrandbits(),uniform(),randrange(),choice(),shuffle()

  • 实例6:圆周率的运算
from random import random
from time import perf_counter
DARTS = 1000*1000
hits = 0.0
start = perf_counter()
for i in range(1,DARTS+1):
    x,y = random(),random()
    dist = pow(x**2+y**2,0.5)
    if dist <=1.0:
        hits = hits + 1
pi = 4*(hits/DARTS)
print("圆周率是:{}".format(pi))
print("运行时间是:{:.5}s".format(perf_counter()-start))

六、第5周:函数和代码复用

  • 函数的定义与使用
  • 函数的定义与使用

1.函数的理解与定义
2.函数的使用及调用过程
3.函数的参数传递
4.函数的返回值
5.*局部变量和全局变量
6.lambda函数

  • 实例7:7段代码管绘制
  • 代码复用与函数递归

1.代码的复用与模块化设计
2.函数递归的理解
3.*函数递归的调用过程:
函数+分支语句
基例和链条,分别编写相应的代码
4.函数递归实例解析

  • 模块4:pyinstaller库的使用

1.pyinstaller库的基本介绍:将源代码转换成无需源代码的可执行文件
2.使用说明:pyinstaller -F <文件名.py>
3.常用参数

  • 实例8:科赫雪花小包裹
  • 实例7:七段数码管绘制
  • 代码复用与函数递归
  • 模块4:Pylnstaller库的使用
  • 实例8:科赫雪花小包裹

七、第6周

  • 集合类型及操作
  • 集合类型定义

1.集合类型与数学中集合概念一致
2.集合元素之间无序,每个元素唯一,不存在相同元素
3.集合元素不能更改,不能是可变数据类型 #?
4.建立空集合必须使用set()

  • 集合操作符

1.6个操作符
2.4个增强操作符

  • 集合处理方法

这里是引用
在这里插入图片描述

  • 集合类型应用场景

1.包含关系比较
2.数据去重

  • 序列类型及操作
  • 序列类型定义

1.序列是具有先后关系的一组元素
2.序列是一组元素向量,元素类型可以不一样
3.包含:字符串、元组、列表

  • 序列处理函数及方法

1.六个操作符:
在这里插入图片描述
例如:将列表反向输出: ls[::-1]
2.5个函数和方法:
在这里插入图片描述

  • 元组类型及操作
  • 列表类型及操作
  • 实例9:基本统计值计算
  • 字典类型及操作
  • 模块5:jieba库的使用
  • 实例10:文本词频统计

猜你喜欢

转载自blog.csdn.net/weixin_44738882/article/details/89207118