蓝桥云课python代码

news2025/2/25 13:19:41

第一章语言基础

第一节编程基础

1 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程序(自由发挥)

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

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

2 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
"""
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
"""
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'>
"""

# 输入三条边的长度
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
"""

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)

"""
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 常量、变量与运算符

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'>
"""
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'>
"""
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'>
"""

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'>
"""

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
"""

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
"""

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条件表达式和逻辑表达式

条件表达式

a,b,c,d = 5,6,7,5
e = a > b
f = a < c
g = a != d
h = a + 1 >= b

print(e)
print(f)
print(g)
print(h)

"""
False
True
False
True
"""

逻辑表达式 

a = 5
b = not a # False
c = not b # True
d = not(a and c) # False
e = ((c - 1) or (d + 1)) # 1
f = ((c - 1) or (d + 2)) # 2
print(b,c,d,e,f)
print(type(e)) # <class 'int'>

 

url = "Hello World"
print("False and xxx")
print(False and print(url))
print()

print("True and xxx")
print(print((url)))
print(True and print((url)))
print()

print("False or xxx")
print(False or print(url))
print()

print("True or xxx")
print(print((url)))
print(True or print((url)))
print()

"""
False and xxx
False

True and xxx
Hello World
None
Hello World
None

False or xxx
Hello World
None

True or xxx
Hello World
None
True
"""

 

# 算术运算符>关系运算符>逻辑运算符>赋值运算符
x = 1>1 or 3<4 or 4>5 and 2>1 and 9>8 or 7<6
print(x)
x = 1>1 or print("111") or 3<4 or 4>5 and 2>1 and 9>8 or 7<6
print(x)
x = 1>1 or 3<4 or print("111") or 4>5 and 2>1 and 9>8 or 7<6
print(x)

"""
True
111
True
True
"""

# not是单目运算符,优先级较高
x = not 2>1 and 3<4 or 4>5 and 2>1 and 9>8 or 7<6
# x = (not 2)>1 and 3<4 or 4>5 and 2>1 and 9>8 or 7<6
# x = 0>1 and 3<4 or 4>5 and 2>1 and 9>8 or 7<6
# x = False or 4>5 and 2>1 and 9>8 or 7<6
# x = False and 2>1 and 9>8 or 7<6
# x = False and 9>8 or 7<6
# x = False or 7<6
# x = False
print(x) # False

 

a = int(input())
b = int(input())
c = int(input())

d = a == 100 or b == 100 or c ==100
e = (a>90 and b>90) or (a>90 and c>90) or (b>90 and c>90)
f = a>80 and b>80 and c>80
answer = d or e or f
print(answer)

"""
70
70
70
False
"""

 

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.coloradmin.cn/o/2304901.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

c#丰田PLC ToyoPuc TCP协议快速读写 to c# Toyota PLC ToyoPuc读写

源代码下载 <------下载地址 历史背景与发展 TOYOPUC协议源于丰田工机&#xff08;TOYODA&#xff09;的自动化技术积累。丰田工机成立于1941年&#xff0c;最初是丰田汽车的机床部门&#xff0c;后独立为专注于工业机械与控制系统的公司。2006年与光洋精工&#xff08;Ko…

深入解析-无状态服务-StatefulSet (一)

一、有状态服务 VS 无状态服务 1.无状态服务介绍 1.数据方面&#xff1a;无状态服务不会在本地存储持久化数据.多个实例可以共享相同的持久化数据 2.结果方面&#xff1a;多个服务实例对于同一个用户请求的响应结果是完全一致的 3.关系方面&#xff1a;这种多服务实例之间是…

hackmyvm-buster

题目地址 信息收集 主机发现 ┌──(root㉿kali)-[/home/kali] └─# arp-scan -I eth1 192.168.56.0/24 Interface: eth1, type: EN10MB, MAC: 00:0c:29:34:da:f5, IPv4: 192.168.56.103 WARNING: Cannot open MAC/Vendor file ieee-oui.txt: Permission denied WARNING: C…

【原创】Windows11安装WSL“无法解析服务器的名称或地址”问题解决方法

原因分析 出现这个问题一开始以为WSL设置了某个服务器&#xff0c;但是通过运行 nslookup www.microsoft.com 出现下面的提示 PS C:\Windows\system32> nslookup www.microsoft.com 服务器: UnKnown Address: 2408:8000:XXXX:2b00:8:8:8:8非权威应答: 名称: e13678…

网页制作08-html,css,javascript初认识のhtml使用框架结构,请先建立站点!

框架一般由框架集和框架组成。 框架集就像一个大的容器&#xff0c;包括所有的框架&#xff0c;是框架的集合。 框架是框架集中一个独立的区域用于显示一个独立的网页文档。 框架集是文件html&#xff0c;它定义一组框架的布局和属性&#xff0c;包括框架的数目&#xff0c;框架…

【Vscode 使用】集合1

一、使用make工具管理工程 windows下&#xff0c;下载mingw64&#xff0c;配置好mingw64\bin 为 Win10系统全局变量后。 在mingw64/bin目录下找到mingw32-make.exe工具。复制一份改名为&#xff1a;make.exe&#xff0c;没错&#xff0c;就是那么简单&#xff0c;mingw64自带m…

文章精读篇——用于遥感小样本语义分割的可学习Prompt

题目&#xff1a;Learnable Prompt for Few-Shot Semantic Segmentation in Remote Sensing Domain 会议&#xff1a;CVPR 2024 Workshop 论文&#xff1a;10.48550/arXiv.2404.10307 相关竞赛&#xff1a;https://codalab.lisn.upsaclay.fr/competitions/17568 年份&#…

解决 kubeasz 安装k8s集群跨节点pod 无法使用cluster ip通讯问题

问题描述 使用kubeasz搭建k8s集群后使用的配置文件 # etcd cluster should have odd member(s) (1,3,5,...) [etcd] 192.168.xx.22# master node(s) [kube_master] 192.168.xx.22# work node(s) [kube_node] 192.168.xx.9 192.168.xx.22# [optional] harbor server, a privat…

Docker 搭建 Nginx 服务器

系列文章目录 Docker 搭建 Nginx 服务器 系列文章目录前言一、准备工作二、设置 Nginx 容器的目录结构三、启动一个临时的 Nginx 容器来复制配置文件四、复制 Nginx 配置文件到本地目录五、删除临时 Nginx 容器六、创建并运行 Nginx 容器&#xff0c;挂载本地目录七、修改 ngin…

Spring AI + 大模型开发应用

JAVA SpringAI 大模型开发AI应用DEMO 前言JAVA项目创建示例 前言 在当今快速发展的技术领域&#xff0c;人工智能&#xff08;AI&#xff09;已经成为推动创新和变革的重要力量。然而&#xff0c;AI应用的开发过程往往复杂且耗时&#xff0c;需要开发者具备深厚的技术背景和丰…

【C++11】 并发⽀持库

&#x1f308; 个人主页&#xff1a;Zfox_ &#x1f525; 系列专栏&#xff1a;C从入门到精通 目录 前言&#xff1a;&#x1f680; 并发⽀持库一&#xff1a;&#x1f525; thread库 二&#xff1a;&#x1f525; this_thread 三&#xff1a;&#x1f525; mutex 四&#xff1…

Windows 11【1001问】如何下载Windows 11系统镜像

随着科技的不断进步&#xff0c;操作系统也在不断地更新换代。Windows 11作为微软最新一代的操作系统&#xff0c;带来了许多令人兴奋的新特性与改进&#xff0c;如全新的用户界面、更好的性能优化以及增强的安全功能等。对于想要体验最新技术或者提升工作效率的用户来说&#…

视觉分析之边缘检测算法

9.1 Roberts算子 Roberts算子又称为交叉微分算法&#xff0c;是基于交叉差分的梯度算法&#xff0c;通过局部差分计算检测边缘线条。 常用来处理具有陡峭的低噪声图像&#xff0c;当图像边缘接近于正45度或负45度时&#xff0c;该算法处理效果更理想。 其缺点是对边缘的定位…

深度学习-6.用于计算机视觉的深度学习

Deep Learning - Lecture 6 Deep Learning for Computer Vision 简介深度学习在计算机视觉领域的发展时间线 语义分割语义分割系统的类型上采样层语义分割的 SegNet 架构软件中的SegNet 架构数据标注 目标检测与识别目标检测与识别问题两阶段和一阶段目标检测与识别两阶段检测器…

【大模型】蓝耘智算云平台快速部署DeepSeek R1/R3大模型详解

目录 一、前言 二、蓝耘智算平台介绍 2.1 蓝耘智算平台是什么 2.2 平台优势 2.3 应用场景 2.4 对DeepSeek 的支持 2.4.1 DeepSeek 简介 2.4.2 DeepSeek 优势 三、蓝耘智算平台部署DeepSeek-R1操作过程 3.1 注册账号 3.1.1 余额检查 3.2 部署DeepSeek-R1 3.2.1 获取…

《计算机视觉》——图像拼接

图像拼接 图像拼接是将多幅有重叠区域的图像合并成一幅全景或更大视角图像的技术&#xff0c;以下为你详细介绍&#xff1a; 原理&#xff1a;图像拼接的核心原理是基于图像之间的特征匹配。首先&#xff0c;从每幅图像中提取独特的特征点&#xff0c;如角点、边缘点等&#x…

element实现需同时满足多行合并和展开的表格

element实现需同时满足多行合并和展开的表格 需求描述: 以下面这张图为例&#xff0c;此表格的“一级表格”这一行可能存在多行数据&#xff0c;这种情况下需要将“一级指标”&#xff0c;“一级指标扣分xxx”,“一级指标关联xxx”这三列数据的行展示根据后面数据&#xff08…

气象干旱触发水文(农业)干旱的概率及其触发阈值的动态变化-贝叶斯copula模型

前言 在干旱研究中&#xff0c;一个关键的科学问题是&#xff1a;在某一地区发生不同等级的气象干旱时&#xff0c;气象干旱会以何种概率引发不同等级的水文干旱、农业干旱和地下水干旱&#xff1f;换句话说&#xff0c;气象干旱的不同程度会分别引发其他类型干旱的哪种等级&a…

系统学习算法:专题十二 记忆化搜索

什么是记忆化搜索&#xff0c;我们先用一道经典例题来引入&#xff0c;斐波那契数 题目一&#xff1a; 相信一开始学编程语言的时候&#xff0c;就一定碰到过这道题&#xff0c;在学循环的时候&#xff0c;我们就用for循环来解决&#xff0c;然后学到了递归&#xff0c;我们又…

c++入门-------命名空间、缺省参数、函数重载

C系列 文章目录 C系列前言一、命名空间二、缺省参数2.1、缺省参数概念2.2、 缺省参数分类2.2.1、全缺省参数2.2.2、半缺省参数 2.3、缺省参数的特点 三、函数重载3.1、函数重载概念3.2、构成函数重载的条件3.2.1、参数类型不同3.2.2、参数个数不同3.2.3、参数类型顺序不同 前言…