蓝桥云课python代码

news/2025/2/25 11:48:28

第一章语言基础

第一节编程基础

1 python开发环境

第一个Python程序

python"># 打印"Hello World"
print("Hello World")

# 打印2的100次方
print(2 ** 100)

# 打印1+1=2
print("1+1=",1 + 1)

"""
Hello World
1267650600228229401496703205376
1+1= 2
"""

利用Python编写自己的第一个Python程序(自由发挥)

python">print("我是python,你是谁?")
a = input()
print("我知道了,你是",a)

"""
我是python,你是谁?
小潘
我知道了,你是 小潘
"""

2 python输入与输出

python"># 默认以空格分隔,默认以换行结尾
print("Hello","World",123,sep = '+')
print("Hello","World",123,sep = '-')
print("Hello","World",123)

print('-'*20)
print("Hello","World",123,sep = '+',end='?')
print("Hello","World",123,sep = '-')
print("Hello","World",123,end="apple")
print("11111")

"""
Hello+World+123
Hello-World-123
Hello World 123
--------------------
Hello+World+123?Hello-World-123
Hello World 123apple11111
"""
python">print(1)

print("Hello World")

a = 1
b = 'running'
print(a,b)

print("aaa""bbb")
print("aaa","bbb")

print("www","lanqiao","cn",sep='.')

"""
1
Hello World
1 running
aaabbb
aaa bbb
www.lanqiao.cn
"""
python">a = input() # 输入整数123,input()函数把输入的都转换成字符串
print(type(a)) # 输出a的类型
a = int(a) # 转换成整数
print(type(a)) # 输出a的类型

a = input("input:") #输入字符串Hello
print(type(a)) # 输出a的类型

"""
123
<class 'str'>
<class 'int'>
input:Hello
<class 'str'>
"""

python"># 输入三条边的长度
a = int(input("第一条边为:"))
b = int(input("第一条边为:"))
c = int(input("第一条边为:"))

# 计算半周长
p = (a+b+c)/2
s = p*(p-a)*(p-b)*(p-c)
s = s**0.5

# 输出面积
print("三角形面积是:",s)

"""
第一条边为:3
第一条边为:4
第一条边为:5
三角形面积是: 6.0
"""

python">a = int(input("请输入a的值:"))
b = int(input("请输入b的值:"))
# 检查输入是否为正整数
if a <= 0 or b <= 0:
    print("输入的必须是正整数。")
else:
    print("a+b=", a + b)
    print("a-b=", a - b)
    print("a*b=", a * b)
    print("a/b=", a / b)
    print("a^b=", a ** b)

python">"""
a,b = int(input("何时开始")),int(input("何分开始"))
c,d = int(input("何时停止")),int(input("何分停止"))
"""
a = int(input("何时开始"))
b = int(input("何分开始"))
c = int(input("何时停止"))
d = int(input("何分停止"))
e = c - a
f = d - b
print("总共游泳:",e*60+f,"分钟")

"""
何时开始12
何分开始0
何时停止13
何分停止1
总共游泳: 61 分钟
"""

3 常量、变量与运算符

python">a = 2 + 3
print(a)

a = 3 - 2
print(a)

a = 3/2
print(a)

a = 3**2
print(a)

a = 0.1 + 0.1
print(a)

a = 0.1 + 0.2
print(a)

a = 0.1 * 3
print(a)

"""
age = 23
message = "Happy " + age + "rd Birthday!"
print(message)
"""

age = 23
message = "Happy " + str(age) + "rd Birthday!"
print(message)
print(type(message))

"""
5
1
1.5
9
0.2
0.30000000000000004
0.30000000000000004
Happy 23rd Birthday!
<class 'str'>
"""
python">a = 3.7
print(a,type(a))

a = int(a)
print(a,type(a))

a = -1.5
print(a,type(a))

a = int(a)
print(a,type(a))

a = 1.9999
print(a,type(a))

a = int(a)
print(a,type(a))

a = 1.9999 + 0.001
print(a,type(a))

a = int(a)
print(a,type(a))

"""
3.7 <class 'float'>
3 <class 'int'>
-1.5 <class 'float'>
-1 <class 'int'>
1.9999 <class 'float'>
1 <class 'int'>
2.0009 <class 'float'>
2 <class 'int'>
"""
python">a = 5
print(a,type(a))

a = bool(a)
print(a,type(a))

a = 0
print(a,type(a))

a = bool(a)
print(a,type(a))

a = 0.0
print(a,type(a))

a = bool(a)
print(a,type(a))

a = -1
print(a,type(a))

a = bool(a)
print(a,type(a))

a = True
print(a,type(a))

a = bool(a)
print(a,type(a))

a = True
print(a,type(a))

a = str(a)
print(a,type(a))

"""
5 <class 'int'>
True <class 'bool'>
0 <class 'int'>
False <class 'bool'>
0.0 <class 'float'>
False <class 'bool'>
-1 <class 'int'>
True <class 'bool'>
True <class 'bool'>
True <class 'bool'>
True <class 'bool'>
True <class 'str'>
"""

python">a = 10
print("a=",a,"type(a)=",type(a))
print("float(a)=",float(a),"type(float(a))=",type(float(a)))
print("bool(a)=",bool(a),"type(bool(a))=",type(bool(a)))
print()

b = 7.8
print("b=",b,"type(b)=",type(b))
print("str(b)=",int(b),"type(str(b))=",type(int(b)))
print("str(b)=",str(b),"type(str(b))=",type(str(b)))
print()

c = "12.3"
print("c=",c,"type(c)=",type(c))
print("float(c)=",float(c),"type(float(c))=",type(float(c)))

"""
a= 10 type(a)= <class 'int'>
float(a)= 10.0 type(float(a))= <class 'float'>
bool(a)= True type(bool(a))= <class 'bool'>

b= 7.8 type(b)= <class 'float'>
str(b)= 7 type(str(b))= <class 'int'>
str(b)= 7.8 type(str(b))= <class 'str'>

c= 12.3 type(c)= <class 'str'>
float(c)= 12.3 type(float(c))= <class 'float'>
"""

python">a = 25
b = 10
# 除法运算符
c = a/b
print(c,type(c))
# 整除运算符
c = a//b
print(c,type(c))
# 转换成浮点数
c = float(c)
print(c,type(c))

"""
2.5 <class 'float'>
2 <class 'int'>
2.0 <class 'float'>
"""

a = 25
b = 10
# 关系运算符,运算结果为True或者False
c = a == b
print(c,type(c))
c = a > b
print(c,type(c))
c = a < b
print(c,type(c))

"""
False <class 'bool'>
True <class 'bool'>
False <class 'bool'>
"""

a = 25
b = 10
#赋值运算符,将等号右边的运算结果存入等号左边的变量
c = a + b
print(c,type(c))
# c = c + a
c += a
print("c=",c)
# c = c/a
c /= a
print("c=",c)

"""
35 <class 'int'>
c= 60
c= 2.4
"""

python">a = 25
b = 10
# 并且:两者均为True才为True
c = a > 0 and b > 0
print(c)
# 或者:只要有一者为True即为True
c = a < 0 or b > 5
print(c)
# 非,not,True -> False,False -> True
c = not a
print(c)

"""
True
True
False
"""

python">def calculator():
    while True:
        try:
            # 输入第一个操作数
            operand1 = input("请输入第一个操作数(可以是整数、浮点数、字符串或布尔值):")
            operand1 = eval(operand1)

            # 输入运算符
            operator = input("请输入运算符(+、-、*、/、//、%、**、==、!=、>、<、>=、<=、and、or、not、in、is、is not):")

            # 输入第二个操作数
            operand2 = input("请输入第二个操作数(可以是整数、浮点数、字符串或布尔值):")
            operand2 = eval(operand2)

            # 执行运算
            if operator == "+":
                result = operand1 + operand2
            elif operator == "-":
                result = operand1 - operand2
            elif operator == "*":
                result = operand1 * operand2
            elif operator == "/":
                if operand2 == 0:
                    print("错误:除数不能为零")
                    continue
                result = operand1 / operand2
            elif operator == "//":
                if operand2 == 0:
                    print("错误:除数不能为零")
                    continue
                result = operand1 // operand2
            elif operator == "%":
                if operand2 == 0:
                    print("错误:除数不能为零")
                    continue
                result = operand1 % operand2
            elif operator == "**":
                result = operand1 ** operand2
            elif operator == "==":
                result = operand1 == operand2
            elif operator == "!=":
                result = operand1 != operand2
            elif operator == ">":
                result = operand1 > operand2
            elif operator == "<":
                result = operand1 < operand2
            elif operator == ">=":
                result = operand1 >= operand2
            elif operator == "<=":
                result = operand1 <= operand2
            elif operator == "and":
                result = operand1 and operand2
            elif operator == "or":
                result = operand1 or operand2
            elif operator == "not":
                result = not operand1
            elif operator == "in":
                if isinstance(operand1, (list, tuple, str)) and operand2 in operand1:
                    result = True
                else:
                    result = False
            elif operator == "is":
                result = operand1 is operand2
            elif operator == "is not":
                result = operand1 is not operand2
            else:
                print("未知运算符")
                continue

            # 输出结果
            print(f"结果:{result}")

        except Exception as e:
            print(f"发生错误:{e}")
            continue

        # 询问是否继续或退出
        continue_calc = input("是否继续计算?(y继续/n退出):")
        if continue_calc.lower() == 'n':
            print("退出程序")
            break

if __name__ == "__main__":
    calculator()

第二节选择结构

1条件表达式和逻辑表达式

2 if语句

第三节循环结构

1for语句

2while语句

3循环嵌套

第四节基础数据结构

1列表与元组

2字符串

3字典

4集合

5日期和时间

第五节函数

1函数的定义与使用

2math

3collections

4heapq

5functool

6itertools

第六节类的定义与使用

1类的定义与使用

2常用库函数

第七节实践应用

1自定义排序

2二分查找

第二章基础算法

第一节排序

1冒泡排序

2选择排序

3插入排序

4快速排序

5归并排序

6桶排序

第二节基础算法

1时间复杂度

2枚举

3模拟

4递归

5进制转换

6前缀和

7差分

8离散化

9贪心

10双指针

11二分

12倍增

13构造

14位运算

第三章搜索

第一节DFS基础

第二节DFS回溯

第三节DFS剪枝

第四节记忆化搜索

第四章动态规划

第一节动态规划基础

1线性DP

2二维DP

3LIS

4LCS

第二节背包问题

1背包

2完全背包

3多重背包

4单调队列多重背包

5二维费用背包&分组背包

第三节树形DP

1自上而下树形DP

2自下而上树形DP

3路径相关树形DP

4换根DP

5区间DP

6状压DP

7数位DP

8期望DP

第五章字符串

第一节KMP&字符串哈希

第二节Manacher

第三节tire

第六章数学

第一节线性代数与矩阵运算&数论

1矩阵乘法

2整除&同余&GCD&LCM

3高斯消元

4行列式

5素数朴素判定&埃氏筛法

6唯一分解定理

7快速幂

8费马小定理&逆元

9素数筛

10裴蜀定理

11欧拉函数&欧拉降幂

第二节组合数学

1计数原理

2排列组合专项

第七章数据结构

第一节基础数据结构

1链表、栈、队列

2堆

3ST表

4并查集基础

5可撤销并查集

6带权并查集

第二节基础的树上问题

1树的基本概念

2树的遍历

3树的直径与重心

4LCA

5树上差分

6DFS序

7树链刨分

第三节树形数据结构

1树状数组基础

2二位树状数组

3树状数组上二分

4线段树-动态开点

5线段树-标记永久化

6线段树维护矩阵

7线段树维护哈希

8可持久化线段树

9扫描线与二维树点

10平衡树-splay

11平衡树-FHQ_Treap

第四节单调数据结构

1单调栈

第五节分块

1分块基础

2普通莫队

第八章图论

第一节图的基础

1图的基本概念

2DFS&BFS

第二节拓扑排序

1基础拓扑排序

第三节最短路

1Floyd

2Dijkstra

3Johnson

第四节生成树

1Kruskal

2Prim

第九章计算几何

第一节计算几何基础

第二节二维计算几何基础

第三节点积和叉积

第四节点和线的关系

第五节线和线的关系

第六节任意多边形面积计算

直播带练

第一次

第二次

第三次

第四次

第五次

第六次

第七次


http://www.niftyadmin.cn/n/5865459.html

相关文章

Spring 源码硬核解析系列专题(一):IoC 容器的初始化过程

Spring 框架作为 Java 生态中最经典的开源项目之一,其核心魅力在于 IoC(控制反转)和 DI(依赖注入)的优雅实现。本系列将深入 Spring 源码,带你从零到一解剖其底层逻辑。本篇作为开篇,我们将聚焦 IoC 容器的初始化过程,以 ClassPathXmlApplicationContext 为例,逐步揭开…

【python】提取word\pdf格式内容到txt文件

一、使用pdfminer提取 import os import re from pdfminer.high_level import extract_text import docx2txt import jiebadef read_pdf(file_path):"""读取 PDF 文件内容:param file_path: PDF 文件路径:return: 文件内容文本"""try:text ext…

Skyeye 云智能制造办公系统 VUE 版本 v3.15.10 发布

Skyeye 云智能制造&#xff0c;采用 Springboot winUI 的低代码平台、移动端采用 UNI-APP。包含 30 多个应用模块、50 多种电子流程&#xff0c;CRM、PM、ERP、MES、ADM、EHR、笔记、知识库、项目、门店、商城、财务、多班次考勤、薪资、招聘、云售后、论坛、公告、问卷、报表…

突破性能极限:DeepSeek开源FlashMLA解码内核技术解析

引言&#xff1a;大模型时代的推理加速革命 在生成式AI大行其道的今天&#xff0c;如何提升大语言模型的推理效率已成为行业焦点。DeepSeek团队最新开源的FlashMLA项目凭借其惊人的性能表现引发关注——在H800 GPU上实现580 TFLOPS计算性能&#xff0c;这正是大模型推理优化的…

基于SpringBoot和Leaflet的邻省GDP可视化实战

目录 前言 一、技术实现路径 1、空间数据检索 2、数据展示检索流程 二、SpringBoot后台实现 1、模型层实现 2、控制层实现 三、WebGIS前端实现 1、控制面展示 2、成果展示 四、总结 前言 在数字化浪潮席卷全球的今天&#xff0c;数据已成为驱动社会经济发展、指导政策…

从入门到精通Rust:资源库整理

今天给大家分享一些优质的Rust语言学习资源&#xff0c;适合不同水平的学习者。前三个官方资源是我Rust语言的启蒙老师&#xff0c;非常平易近人。 官方资源 The Rust Programming Language (The Book) 链接: https://doc.rust-lang.org/book/ 简介: 官方权威指南&#xff0c…

Flutter 上的 Platform 和 UI 线程合并是怎么回事?它会带来什么?

Flutter 在 3.29 发布了一个「重大」调整&#xff1a;从 3.29 开始&#xff0c;Android 和 iOS 上的 Flutter 将在应用的主线程上执行 Dart 代码&#xff0c;并且不再有单独的 Dart UI 线程 也许一些人对于这个概念还比较陌生&#xff0c;有时间可以看看以前发过的 《深入理解…

多线程运行测试文件

目录 一、测试时间对比多线程单线程 二、python多线程实现三、阻塞主线程确保所有子进程/线程执行完毕 跑测试的时候想提高效率&#xff0c;多个模型的跑。之前设计的就是for循环&#xff0c;等一个模型跑完另一个跑&#xff0c;不过时间上比较慢。想试试多线程的效果。其实多开…