1.while循环语句

条件为布尔类型或比较运算


要提前定义变量
猜数字:

2.While 嵌套循环





3.For 循环



遍历循环、无循环条件
5.range语句






学习番外:
打开.txt文件:
# 导入必要的库
import os
# 定义文件路径
file_path = r"C:\Users\Yu\Desktop\Work\Python\Python.txt"
# 检查文件是否存在
if os.path.exists(file_path):
try:
# 打开文件并读取内容
with open(file_path, "r", encoding='utf-8') as file:
content = file.read()
print(content)
except Exception as e:
print(f"无法读取文件:{e}")
else:
print("文件不存在")

4153



被折叠的 条评论
为什么被折叠?



