当前位置:首页>python>《Python基础及应用》第4章 循环程序设计-4.3 循环的人为退出

《Python基础及应用》第4章 循环程序设计-4.3 循环的人为退出

  • 2026-04-20 13:10:24
《Python基础及应用》第4章 循环程序设计-4.3 循环的人为退出

教学平台:Anaconda Jupyter Notebook

第4章 循环程序设计

4.3 循环的人为退出

📚 学习目标

掌握break语句的使用方法和应用场景

掌握continue语句的使用方法及其对else子句的影响

熟练运用random库的各种函数生成随机数

能够综合运用循环控制语句解决实际问题

理解breakcontinue的本质区别

4.3.1 break语句

一、什么是break语句

break是Python中的循环控制语句,用于立即终止当前循环,跳出循环体,执行循环后的语句。

语法

break

作用:在for循环或while循环中,一旦执行到break,循环立即结束,无论遍历是否完成或条件是否仍为真。

二、break语句的执行流程

流程图

循环开始┌→ 执行循环体遇到break?──是──→ 立即跳出循环↓否继续循环执行循环后语句└──────┘

关键特征: - break只能用在循环内部forwhile) - break立即终止整个循环,不是跳过某次迭代 - 如果循环带有else子句,break会导致else不执行

三、break语句的典型应用场景

场景1:搜索/查找(找到即停)

示例:在CK学生名单中查找特定学号

# CK学生名单students = ["CK2024001""CK2024005""CK2024009""CK2024012""CK2024015"]target = "CK2024009"  # 要查找的目标print(f"🔍 开始查找学号:{target}")for i, student in enumerate(students):    '''    1.为什么要用enumerate():    如果我们只用 for student in students:,我们只能拿到学生的学号(如 "CK2024001"),但不知道他是第几个(索引是多少)。    如果我们只用 for i in range(len(students)):,我们可以拿到索引 i,但取名字时要写 students[i],代码显得啰嗦。    enumerate() 的作用:它能同时返回两个值:索引(下标)和元素值。    2.工作原理:    假设 students = ["李明", "王强", "赵敏"]。    enumerate(students) 会生成一个类似 (0, "李明"), (1, "王强"), (2, "赵敏") 的序列。    i 自动接收索引(从 0 开始:0, 1, 2...)。    student 自动接收对应的名字("李明", "王强"...)。    '''    print(f"检查第{i+1}位:{student}")    if student == target:        print(f"✅ 找到目标!位置:第{i+1}位")        break  # 找到后立即停止查找print("查找结束")

输出

🔍 开始查找学号:CK2024009检查第1位:CK2024001检查第2位:CK2024005检查第3位:CK2024009✅ 找到目标!位置:第3位查找结束

注意:找到CK2024009后循环立即终止,不再检查后面的学生

场景2:数据验证(输入正确即停)

示例:CK图书馆登录验证(最多尝试3次)

# 预设正确密码correct_password = "CKlib2024"attempts = 0max_attempts = 3print("📚 CK图书馆系统登录")while attempts < max_attempts:    attempts += 1    password = input(f"第{attempts}次尝试,请输入密码:")    if password == correct_password:        print("✅ 登录成功!欢迎进入CK图书馆")        break  # 登录成功,跳出循环    else:        remaining = max_attempts - attempts        if remaining > 0:            print(f"❌ 密码错误,还剩{remaining}次机会")        else:            print("🚫 密码错误次数过多,账户已锁定")# 判断登录结果(循环外)if attempts >= max_attempts and password != correct_password:    print("请联系管理员解锁账户")

知识串联:回忆4.2节学习的while循环,break提供了一种灵活的退出方式,比单纯依赖条件更直观。

场景3:异常处理(遇到特殊情况立即退出)

示例:CK食堂消费统计(遇到异常数据停止)

# 统计一周消费,如果遇到负数(数据错误)立即停止daily_costs = [354228, -5384530]  # 第4天数据异常total = 0print("💰 计算本周食堂消费总额")for day, cost in enumerate(daily_costs, 1):    '''    默认情况下,enumerate 从 0 开始计数(0, 1, 2...)。    第二个参数 1:告诉 Python 从 1 开始计数(1, 2, 3...)。    '''    if cost < 0:        print(f"⚠️ 第{day}天数据异常({cost}元),停止统计!")        break  # 数据异常,立即停止    total += cost    print(f"第{day}天:{cost}元")print(f"累计消费:{total}元")

输出

💰 计算本周食堂消费总额第1天:35元第2天:42元第3天:28元⚠️ 第4天数据异常(-5元),停止统计!累计消费:105元

四、break对else子句的影响(重要!)

核心规则break跳过循环的else

对比示例

# 示例1:正常结束(不使用break)- else会执行print("=== 示例1:正常结束 ===")for i in range(3):    print(f"处理第{i+1}个文件")else:    print("✅ 所有文件处理完成(else执行)")print("\n=== 示例2:使用break中断 ===")# 示例2:使用break中断 - else不会执行for i in range(3):    print(f"处理第{i+1}个文件")    if i == 1:        print("❌ 发现错误,立即停止")        breakelse:    print("✅ 所有文件处理完成(else不执行)")print("程序继续...")

输出

=== 示例1:正常结束 ===处理第1个文件处理第2个文件处理第3个文件✅ 所有文件处理完成(else执行)=== 示例2:使用break中断 ===处理第1个文件处理第2个文件❌ 发现错误,立即停止程序继续...

知识串联:回忆4.1节和4.2节学习的for-elsewhile-else结构,else的触发条件是”循环正常结束”,而break会强制中断循环,导致else不执行。这是设计搜索算法时的重要技巧!

实际应用:搜索算法中的”未找到”提示

# 在CK课程列表中查找"Python"课程courses = ["经济学""数学""英语""物理"]for course in courses:    if course == "Python":        print(f"✅ 找到{course}课程")        breakelse:    # 只有循环完整遍历后才会执行    print("😔 未找到Python课程,建议联系教务处")

🤖 AI辅助学习:4.3.1节

练习1:CK紧急疏散模拟系统

场景:模拟教学楼紧急疏散,一旦所有人员撤离完毕立即停止计时。

AI提示词

请帮我写一个CK教学楼紧急疏散模拟程序,使用break语句。要求:1. 初始化总学生数为500人,每层100人,共5层2. 使用while循环模拟疏散过程:- 每轮循环代表1分钟- 每分钟随机疏散30-50人(使用random.randint)- 显示"第X分钟:已疏散Y人,剩余Z人"3. 一旦剩余人数<=0,立即break并显示"✅ 全员疏散完成!用时X分钟"4. 如果超过20分钟仍未疏散完,也break并显示"⚠️ 疏散超时,请检查"5. 使用time.sleep(0.3)模拟时间流逝6. 最后统计并显示平均每分钟疏散人数

练习2:重庆轻轨到站提醒器

场景:模拟重庆轻轨3号线,用户选择目的地,到站前播报,到站时break。

AI提示词

请帮我写一个重庆轻轨3号线到站提醒程序,使用break语句。要求:1. 定义站点列表(从CK大学附近开始):stations = ["CK大学站", "大学城站", "微电园站", "陈家桥站", "磁器口站", "沙坪坝站", "两路口站", "观音桥站", "红旗河沟站"]2. 让用户输入目的地站点名称3. 使用for循环遍历站点:- 显示"🚇 当前到达:XX站"- 如果当前站就是目的地,显示"✅ 到达目的地,请下车"并break- 否则显示"⏭️ 下一站:XX站"(如果还有下一站)4. 使用time.sleep(0.8)模拟行驶时间5. 如果循环正常结束(没找到站点),else块显示"❌ 该线路不经过此站"6. 添加emoji和分隔线让输出美观

4.3.2 continue语句

一、什么是continue语句

continue是Python中的循环控制语句,用于跳过当前迭代的剩余代码,直接进入下一次循环。

语法

continue

作用:结束本次循环,立即开始下一次循环(如果是for循环,取下一个元素;如果是while循环,重新判断条件)。

二、break vs continue 本质区别

特性

break

continue

作用范围

整个循环

仅当前迭代

后续行为

跳出循环,执行循环后代码

进入下一次循环

循环次数

提前终止,次数减少

次数不变,跳过部分代码

else子句

不执行

正常执行(如果循环完成)

形象比喻: - break = 逃课:直接离开教室,不再回来 - continue = 跳过:这节课不听,去上下一节课

三、continue语句的执行流程

流程图

循环开始┌→ 执行循环体前半部分遇到continue?──是──→ 跳到循环开头(下一次迭代)↓否执行循环体后半部分└──────┘(继续下一次循环或结束)

四、continue的典型应用场景

场景1:跳过特定条件的数据处理

示例:统计CK学生活动参与率(跳过无效数据)

# 学生活动签到数据(-1表示未签到,0表示请假)attendance = [11, -1101, -1110]present_count = 0valid_count = 0print("📋 CK学生活动签到统计")for i, status in enumerate(attendance, 1):    if status == -1:        print(f"学号{i}:未签到,跳过统计")        continue  # 跳过未签到的学生    if status == 0:        print(f"学号{i}:请假,跳过统计")        continue  # 跳过请假的学生    # 以下代码只有status为1时才会执行    present_count += 1    valid_count += 1    print(f"学号{i}:已签到 ✅")print(f"\n实际参与:{present_count}人")print(f"应到人数:{len(attendance)}人")print(f"参与率:{present_count/len(attendance)*100:.1f}%")

输出

📋 CK学生活动签到统计学号1:已签到 ✅学号2:已签到 ✅学号3:未签到,跳过统计学号4:已签到 ✅学号5:请假,跳过统计学号6:已签到 ✅学号7:未签到,跳过统计学号8:已签到 ✅学号9:已签到 ✅学号10:请假,跳过统计实际参与:6人应到人数:10人参与率:60.0%

知识串联:回忆第3章学习的if判断,continue通常与if配合使用,实现”不符合条件就跳过”的逻辑。

场景2:过滤特定元素

示例:CK成绩统计(跳过缺考学生)

# CK班级成绩(-1表示缺考)scores = [8592, -178, -18895, -18290]total = 0count = 0print("📊 班级成绩统计(跳过缺考)")for score in scores:    if score == -1:        continue  # 跳过缺考学生,不纳入统计    total += score    count += 1    print(f"有效成绩:{score}分")average = total / count if count > 0 else 0print(f"\n统计结果:")print(f"  参考人数:{count}人")print(f"  平均分:{average:.2f}分")print(f"  缺考人数:{scores.count(-1)}人")

五、continue对else子句的影响(重要!)

核心规则continue不会跳过else子句,只有循环正常完成else才会执行

对比示例

# 示例1:使用continue - else会执行print("=== continue不影响else ===")for i in range(5):    if i == 2:        print(f"跳过{i}")        continue    print(f"处理{i}")else:    print("✅ 循环正常完成,else执行")print("\n=== break会跳过else ===")# 示例2:使用break - else不会执行for i in range(5):    if i == 2:        print(f"在{i}处break")        break    print(f"处理{i}")else:    print("❌ 这行不会执行")

输出

=== continue不影响else ===处理0处理1跳过2处理3处理4✅ 循环正常完成,else执行=== break会跳过else ===处理0处理1在2处break

关键总结: - continue = 跳过本次,继续下次,最终循环会正常完成 → else执行 - break = 直接终止整个循环 → else不执行

实际应用:数据处理中的”跳过无效,完成提示”

# 处理CK学生信息,跳过无效数据,完成后提示students = ["张三""""李四""王五""""赵六"]for student in students:    if student == "":  # 空字符串表示数据缺失        continue  # 跳过,继续处理下一个    print(f"处理学生:{student}")else:    # 无论跳过了多少空字符串,只要遍历完所有元素就执行    print("✅ 所有学生信息处理完毕")

知识串联:回忆4.1节和4.2节学习的else子句,它的设计初衷是”循环正常完成的奖励”。continue只是跳过某次迭代,不影响循环的”完整性”,所以else会执行;而break是”强制终止”,破坏了完整性,所以else不执行。

🤖 AI辅助学习:4.3.2节

练习1:CK成绩等级筛选器

场景:批量处理学生成绩,只统计及格(>=60)且非优秀(<90)的学生(中等生关注)。

AI提示词

请帮我写一个CK成绩等级筛选程序,使用continue语句。要求:1. 创建一个成绩列表(包含0-100的各种分数,以及-1表示缺考):scores = [85, 92, 58, 76, -1, 88, 95, 45, 82, 90, 30, -1, 78]2. 使用for循环遍历成绩:- 如果成绩为-1(缺考),显示"缺考,跳过"并continue- 如果成绩<60(不及格),显示"不及格,跳过"并continue- 如果成绩>=90(优秀),显示"优秀生,跳过"并continue- 只有60<=成绩<90时,才统计为"中等生"3. 统计中等生人数,并计算他们的平均分4. 使用else块显示"筛选完成,共找到X名中等生"5. 最后显示所有被跳过的情况统计(缺考X人,不及格X人,优秀X人)6. 使用emoji区分不同等级

练习2:重庆天气数据清洗

场景:清洗一周天气数据,跳过异常值,计算平均温度。

AI提示词

请帮我写一个重庆天气数据清洗程序,使用continue语句。要求:1. 创建一周温度数据(包含异常值-999表示传感器故障):temperatures = [32, 35, -999, 33, 36, -999, 31]2. 使用for循环配合enumerate遍历:- 如果温度为-999,显示"第X天数据异常,跳过"并continue- 否则累加有效温度和天数3. 使用else块显示"✅ 数据清洗完成,有效数据X天"4. 计算并显示平均温度(保留1位小数)5. 显示最高温和最低温(只考虑有效数据)6. 使用time.sleep(0.3)模拟数据处理过程7. 添加"🌡️"等emoji让输出更生动

4.3.3 random库

一、random库概述

random是Python的标准库,用于生成伪随机数,广泛应用于: - 游戏开发(随机事件、抽奖) - 数据模拟(测试数据生成) - 算法实现(随机算法、蒙特卡洛方法) - 教学示例(猜数字、随机抽题)

导入方式

import random

知识串联:回忆第3章学习的math库导入,random同样是标准库,使用相同的import语法。

二、random库常用函数详解

1. random() - 生成[0.0, 1.0)之间的浮点数

语法random.random()

返回值:0.0 <= x < 1.0 的浮点数

示例

import random# 生成5个随机小数print("🎲 生成5个0-1之间的随机数:")for i in range(5):    num = random.random()    print(f"  第{i+1}个:{num:.4f}")

应用:CK随机抽奖(按概率)

# CK活动抽奖:30%概率中奖print("🎁 CK校园抽奖活动")for student in range(16):    luck = random.random()    if luck < 0.3:  # 30%概率        print(f"学号{student}:中奖!(概率值:{luck:.4f})")    else:        print(f"学号{student}:未中奖(概率值:{luck:.4f})")

2. randint(a, b) - 生成[a, b]之间的整数

语法random.randint(a, b)

参数: - a:下限(包含) - b:上限(包含)

返回值:a <= x <= b 的整数

示例

# 生成CK学号后4位(1000-9999)student_id_suffix = random.randint(10009999)print(f"随机学号:CK20{student_id_suffix}")# 模拟骰子(1-6)dice = random.randint(16)print(f"🎲 掷骰子结果:{dice}")

3. randrange([start,] stop[, step]) - 按步长生成的整数

语法

random.randrange(start, stop, step)或 random.randrange(stop)

参数: - start:起始值(包含,默认0) - stop:终止值(不包含) - step:步长(默认1)

对比:与4.1节学习的range()函数参数完全一致!

示例

# 生成偶数(0-100之间的随机偶数)even = random.randrange(01012)print(f"随机偶数:{even}")# 生成奇数(1-99之间的随机奇数)odd = random.randrange(11002)print(f"随机奇数:{odd}")# 从CK教学楼1-5层随机选一层(只选偶数层)floor = random.randrange(262)  # 24print(f"随机选择{floor}层教室")

知识串联:回忆4.1节学习的range()三种格式,randrange()的参数规则完全相同,只是返回的是随机选择的元素而非序列。

4. getrandbits(k) - 生成k位随机二进制整数

语法random.getrandbits(k)

参数k:位数

返回值:0到2^k - 1之间的整数

示例

# 生成8位随机数(0-255)num8 = random.getrandbits(8)print(f"8位随机数:{num8}(二进制:{num8:08b})")# 生成16位随机数(可用于简单ID)id16 = random.getrandbits(16)print(f"16位随机ID:{id16}")

应用:生成CK临时验证码

# 生成6位数字验证码(0-999999)code = random.getrandbits(20) % 1000000  # 取模确保6print(f"您的CK校园验证码:{code:06d}")  # 不足6位前面补0

5. uniform(a, b) - 生成[a, b]之间的浮点数

语法

random.uniform(ab)

返回值:a <= x <= b 或 a <= x < b 的浮点数(取决于舍入)

示例

# 生成CK学生随机身高(1.5-1.9米)height = random.uniform(1.51.9)print(f"随机身高:{height:.2f}米")# 生成重庆随机温度(夏季,25-40度)temp = random.uniform(25.040.0)print(f"今日重庆温度:{temp:.1f}℃")

6. choice(seq) - 从序列中随机选择元素

语法

random.choice(seq)

参数seq:序列(字符串、列表、元组等)

返回值:序列中的随机一个元素

示例

# CK随机选择食堂canteens = ["一食堂""二食堂""三食堂""清真食堂"]today_canteen = random.choice(canteens)print(f"🍽️ 今天去{today_canteen}吃饭")# 随机选择重庆景点spots = ["洪崖洞""磁器口""长江索道""解放碑"]weekend_plan = random.choice(spots)print(f"🌄 周末去{weekend_plan}玩")

7. shuffle(seq) - 打乱序列顺序(原地修改)

语法random.shuffle(seq)

参数seq:可变序列(列表)

返回值None(直接修改原序列)

⚠️ 重要shuffle直接修改原列表,不返回新列表!

示例

# CK随机考试座位安排students = ["张三""李四""王五""赵六""孙七"]print(f"原始名单:{students}")random.shuffle(students)print(f"随机座位:{students}")

输出

原始名单:['张三', '李四', '王五', '赵六', '孙七']随机座位:['王五', '张三', '孙七', '赵六', '李四']# 顺序已打乱

三、综合应用:网上考试系统选项乱序

场景:CK在线考试系统,为防止作弊,需要随机打乱每道题的选项顺序,但要记录正确答案的新位置。

完整代码

import randomdef shuffle_options(question, options, correct_index):    """    打乱选项顺序,返回新选项列表和正确答案的新位置    question: 题目    options: 选项列表(如["A.北京", "B.上海", "C.重庆", "D.天津"])    correct_index: 原正确答案的索引(0-based)    """    # 创建带索引的选项列表,保留原始位置信息    indexed_options = list(enumerate(options))    # 打乱顺序    random.shuffle(indexed_options)    # 提取新顺序的选项    new_options = [opt for idx, opt in indexed_options]    # 找到正确答案的新位置    new_correct_index = None    for new_idx, (old_idx, opt) in enumerate(indexed_options):        if old_idx == correct_index:            new_correct_index = new_idx            break    return new_options, new_correct_index# 测试:CK大学校史知识题question = "CK大学位于哪个城市?"options = ["A. 北京""B. 上海""C. 重庆""D. 天津"]correct = 2  # 正确答案是"重庆",原索引为2print("=" * 50)print("📝 CK在线考试系统 - 选项乱序演示")print("=" * 50)print(f"题目:{question}")print(f"原始选项:{options}")print(f"正确答案索引:{correct}{options[correct]})\n")# 打乱3次,展示不同结果for i in range(3):    new_opts, new_correct = shuffle_options(question, options, correct)    print(f"--- 第{i+1}次随机 ---")    print(f"新选项顺序:{new_opts}")    print(f"正确答案现在位于索引:{new_correct}")    print(f"对应选项:{new_opts[new_correct]}\n")

输出示例

==================================================📝 CK在线考试系统 - 选项乱序演示==================================================题目:CK大学位于哪个城市?原始选项:['A. 北京', 'B. 上海', 'C. 重庆', 'D. 天津']正确答案索引:2(C. 重庆)--- 第1次随机 ---新选项顺序:['C. 重庆', 'A. 北京', 'D. 天津', 'B. 上海']正确答案现在位于索引:0对应选项:C. 重庆--- 第2次随机 ---新选项顺序:['B. 上海', 'D. 天津', 'C. 重庆', 'A. 北京']正确答案现在位于索引:2对应选项:C. 重庆--- 第3次随机 ---新选项顺序:['D. 天津', 'C. 重庆', 'A. 北京', 'B. 上海']正确答案现在位于索引:1对应选项:C. 重庆

知识串联:回忆第2章学习的列表操作(索引、切片),shuffle直接修改原列表,如果需要保留原列表,必须先copy()

🤖 AI辅助学习:4.3.3节

练习1:CK幸运大转盘

场景:使用random实现一个转盘抽奖,不同奖项有不同概率。

AI提示词

请帮我写一个CK校园幸运大转盘程序,使用random库。要求:1. 定义奖项和概率:prizes = {"一等奖:iPad": 0.05,# 5%"二等奖:耳机": 0.10,# 10%"三等奖:书包": 0.20,# 20%"四等奖:笔记本": 0.30,# 30%"谢谢参与": 0.35# 35%}2. 使用random.random()生成0-1随机数,根据概率区间确定奖项3. 使用random.choice从"恭喜!XX"和"太棒了!XX"等提示语中随机选择显示风格4. 让用户可以连续抽奖(输入"是"继续,"否"退出,使用while循环)5. 统计用户抽奖次数和各奖项获得次数6. 退出时显示统计报告7. 使用emoji装饰不同奖项(🏆🎧🎒📒😊)8. 添加延迟time.sleep(0.5)增加悬念感

练习2:重庆美食随机推荐器

场景:根据用户口味偏好,随机推荐重庆美食。

AI提示词

请帮我写一个重庆美食随机推荐程序,使用random库。要求:1. 创建美食分类字典:foods = {"火锅": ["渝味晓宇", "佩姐老火锅", "大龙燚", "小龙坎"],"小面": ["花市豌杂面", "秦云老太婆摊摊面", "眼镜面"],"串串": ["钢管厂五区小郡肝", "马路边边", "签签牛肉"],"江湖菜": ["杨记隆府", "纯阳老酒馆", "山城老堂口"]}2. 使用random.choice让用户选择想吃的类别(或让用户输入)3. 使用random.choice从该类别中随机推荐一家店4. 使用random.randint生成预计人均消费(30-100元)5. 使用random.uniform生成距离CK大学的距离(1.0-15.0公里)6. 显示完整的推荐信息,包括:- 类别、店名、人均、距离- 使用random.choice随机生成推荐理由(从预设列表中选)7. 询问用户是否满意(不满意则重新推荐,使用while循环)8. 满意后使用random.shuffle打乱该类别所有店铺,显示"您还可以尝试这些"

4.3.4 程序设计实例

实例1:素数判断程序

问题描述: 编程实现输入一个大于1的自然数x,输出它是否为素数的信息。

素数定义:素数是只有1和它自身两个因数的自然数(如2, 3, 5, 7, 11…)。

算法分析: 1. 素数判断:只需检查2到√x之间是否有因数 2. 如果有因数,立即break退出(不是素数) 3. 如果循环正常完成,则是素数(else子句)

完整代码

import mathprint("=" * 50)print("🔢 CK大学素数判断系统")print("=" * 50)# 获取输入x = int(input("请输入一个大于1的自然数:"))# 输入验证while x <= 1:    print("❌ 输入必须大于1")    x = int(input("请重新输入:"))print(f"\n开始判断{x}是否为素数...")# 素数判断算法# 只需检查2到sqrt(x)即可is_prime = True  # 先假设是素数for i in range(2int(math.sqrt(x)) + 1):    if x % i == 0:  # 发现因数        print(f"发现因数:{i}{x} = {i} × {x//i})")        is_prime = False        break  # 发现一个因数就足以判定不是素数,立即退出# 输出结果if is_prime:    print(f"✅ {x}是素数!")    print(f"   因为{x}只能被1和自身整除")else:    print(f"❌ {x}不是素数!")    print(f"   因为它有除了1和自身以外的因数")# 使用for-else的优化版本(供参考)print("\n" + "-" * 50)print("【优化版本】使用for-else结构:")for i in range(2int(math.sqrt(x)) + 1):    if x % i == 0:        print(f"❌ {x}不是素数(发现因数{i})")        breakelse:    # 循环正常完成(没有找到因数)    print(f"✅ {x}是素数!")

运行示例

==================================================🔢 CK大学素数判断系统==================================================请输入一个大于1的自然数:17开始判断17是否为素数...✅ 17是素数!因为17只能被1和自身整除--------------------------------------------------【优化版本】使用for-else结构:✅ 17是素数!

==================================================🔢 CK大学素数判断系统==================================================请输入一个大于1的自然数:20开始判断20是否为素数...发现因数:2(20 = 2 × 10)❌ 20不是素数!因为它有除了1和自身以外的因数--------------------------------------------------【优化版本】使用for-else结构:❌ 20不是素数(发现因数2)

知识串联: - 回忆第2章学习的math.sqrt()求平方根 - 回忆第2章学习的int()类型转换和整除// - 回忆第3章学习的if-else条件判断 - 使用了4.3.1节学习的break语句提前退出 - 使用了4.1节学习的for-else结构简化代码

实例2:猜数字游戏

问题描述: 编程实现一个猜数字的简单游戏: 1. 系统自动生成一个1-100之间的随机整数 2. 提示用户输入数据来猜,最多可以猜20次 3. 超过20次输出”游戏结束!“并结束游戏 4. 猜的过程中: - 输入数字比生成的数字大 → 提示”太大” - 输入数字比生成的数字小 → 提示”太小” - 输入数字和生成的数字相等 → 输出”恭喜你,猜中了!共猜了**次”,结束游戏

完整代码

import randomprint("=" * 50)print("🎮 CK猜数字游戏")print("=" * 50)print("规则:")print("  1. 系统已生成1-100之间的随机整数")print("  2. 你最多可以猜20次")print("  3. 每次猜测后会提示太大或太小")print("=" * 50)# 生成随机数(1-100)target = random.randint(1100)max_attempts = 20# 游戏主循环for attempt in range(1, max_attempts + 1):    # 获取用户输入    guess_input = input(f"\n第{attempt}次猜测(1-100):")    # 输入验证(确保是数字)    if not guess_input.isdigit():        '''         .isdigit() 方法        归属:这是字符串(str)类型的内置方法        功能:检查字符串是否全部由数字字符(0-9)组成。        返回值:            如果是纯数字(如 "88", "0", "12345"),返回 True。            如果包含非数字字符(如 "88a", "12.5", "-5", "  "空格),返回 False。            ⚠️ 重要陷阱(考点):            负数:"-5".isdigit() 返回 False!因为 - 是符号,不是数字字符。            小数:"3.14".isdigit() 返回 False!因为 . 是标点。            空格:" 123 ".isdigit() 返回 False!        '''        print("❌ 请输入有效的整数!")        continue  # 不计入有效次数,继续下一次    guess = int(guess_input)    # 验证范围    if guess < 1 or guess > 100:        print("❌ 请输入1-100之间的数字!")        continue    # 判断猜测结果    if guess > target:        print("📉 太大!再试试小的")    elif guess < target:        print("📈 太小!再试试大的")    else:        # 猜中了!        print("=" * 50)        print(f"🎉 恭喜你,猜中了!")        print(f"   答案就是:{target}")        print(f"   共猜了{attempt}次")        # 评价        if attempt <= 5:            print("   🏆 评价:天才!运气爆棚!")        elif attempt <= 10:            print("   ⭐ 评价:不错!很有潜力!")        elif attempt <= 15:            print("   👍 评价:还可以,继续努力!")        else:            print("   😊 评价:终于猜中了,不容易!")        print("=" * 50)        break  # 猜中了,结束游戏else:    # 循环正常结束(20次都没猜中)    print("\n" + "=" * 50)    print("🚫 游戏结束!")    print(f"   20次机会已用完")    print(f"   正确答案是:{target}")    print("=" * 50)print("感谢游玩CK猜数字游戏!")

运行示例(成功猜中)

==================================================🎮 CK猜数字游戏==================================================规则:1. 系统已生成1-100之间的随机整数2. 你最多可以猜20次3. 每次猜测后会提示太大或太小==================================================第1次猜测(1-100):50📉 太大!再试试小的第2次猜测(1-100):25📈 太小!再试试大的第3次猜测(1-100):37📉 太大!再试试小的第4次猜测(1-100):31🎉 恭喜你,猜中了!答案就是:31共猜了4次⭐ 评价:不错!很有潜力!==================================================感谢游玩CK猜数字游戏!

运行示例(次数用完)

...第19次猜测(1-100):83📈 太小!再试试大的第20次猜测(1-100):91📉 太大!再试试小的==================================================🚫 游戏结束!20次机会已用完正确答案是:87==================================================感谢游玩CK猜数字游戏!

知识串联: - 回忆第2章学习的isdigit()字符串方法验证数字输入 - 回忆第3章学习的if-elif-else多分支判断 - 使用了4.3.3节学习的random.randint()生成随机数 - 使用了4.3.1节学习的break提前结束游戏 - 使用了4.3.2节学习的continue跳过无效输入 - 使用了4.1节学习的for-else处理次数用完的情况

🤖 AI辅助学习:4.3.4节

练习1:CK智能计算器(带错误处理)

场景:实现一个计算器,能够处理各种错误输入,使用break和continue优化流程。

AI提示词

请帮我写一个CK智能计算器,综合使用break、continue和循环。要求:1. 使用while循环让用户可以连续计算:- 输入格式:"数字 运算符 数字"(如"10 + 5")- 输入"退出"则break结束程序2. 使用continue处理以下情况:- 输入格式不正确(不是三部分)- 运算符不在+-*/中- 数字部分无法转换为float都要显示错误提示并continue,让用户重新输入3. 计算功能:- 支持加减乘除- 除法时检查除数是否为0,为0则continue提示"除数不能为0"4. 显示计算结果,并询问是否继续(输入"否"则break)5. 使用else块(或循环后代码)统计并显示:- 本次会话共进行了多少次成功计算- 每种运算各使用了几次(用字典统计)6. 添加emoji区分不同运算(➕➖✖️➗)7. 使用try-except处理数字转换异常(预习第3章异常处理)

练习2:重庆景点探索游戏

场景:设计一个文字冒险游戏,玩家在重庆各景点间随机探索,使用break和continue控制流程。

AI提示词

请帮我写一个"重庆景点探索"文字冒险游戏,综合使用本章所有知识。要求:1. 游戏设定:- 玩家从CK大学出发,目标是到达洪崖洞- 地图包含:CK大学、磁器口、长江索道、解放碑、洪崖洞- 每个地点有随机事件(使用random.choice)2. 游戏机制:- 使用while循环,玩家有10点体力值- 每次移动消耗1点体力,随机移动到下一点(使用random.choice从相邻点选)- 使用continue跳过某些特殊事件(如"遇到堵车,本回合不移动")- 到达洪崖洞或体力耗尽时使用break结束3. 随机事件(每个地点不同):- 好事:体力+1、直接传送、发现美食- 坏事:体力-1、迷路(原地不动)、下雨(延迟)- 使用random.random()决定事件好坏(<0.3坏事,>0.7好事)4. 使用random.shuffle打乱每日事件顺序5. 游戏结束判断:- 成功到达:显示"🎉 成功到达洪崖洞!剩余体力X点"- 体力耗尽:显示"😔 体力耗尽,游戏结束。距离目标还有X站"6. 添加详细的文字描述和emoji,让游戏生动有趣7. 使用for-else或while-else结构添加额外评价

📋 本节知识总结

核心知识点回顾

知识点

关键内容

易错点

break

立即终止整个循环

会导致else不执行

continue

跳过本次,继续下次

不影响else执行

random()

[0.0, 1.0)浮点数

不包含1.0

randint(a,b)

[a,b]整数

包含两端

randrange()

按步长生成的整数

不含终止值

choice(seq)

随机选元素

序列不能为空

shuffle(seq)

打乱列表

原地修改,返回None

break vs continue vs pass 对比

语句

作用

循环是否继续

else是否执行

break

终止循环

❌ 否

❌ 否

continue

跳过本次

✅ 是(下次)

✅ 是

pass

什么都不做

✅ 是(继续当前)

✅ 是

与前面章节的联系

第2章基础 → 第3章分支 → 第4.1-4.2节循环 → 第4.3节循环控制 变量类型if判断for/whilebreak 类型转换逻辑运算range()continue 字符串方法比较运算循环嵌套random库 math库

附录:random库函数速查表

函数

语法

返回值范围

示例

random()

random.random()

[0.0, 1.0)

0.374448871756

randint()

random.randint(1, 10)

[1, 10]

7

randrange()

random.randrange(0, 100, 2)

0,2,4…98

42

getrandbits()

random.getrandbits(8)

0-255

157

uniform()

random.uniform(1.5, 2.5)

[1.5, 2.5]

1.8934

choice()

random.choice([1,2,3])

序列中元素

2

shuffle()

random.shuffle(list)

None(修改原列表)

-

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-04-20 23:36:07 HTTP/2.0 GET : https://f.mffb.com.cn/a/484565.html
  2. 运行时间 : 0.128638s [ 吞吐率:7.77req/s ] 内存消耗:4,941.86kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=f5d70790e1d2c32cfed15c00bbfb2a58
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000420s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000508s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000231s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000277s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000476s ]
  6. SELECT * FROM `set` [ RunTime:0.002944s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000614s ]
  8. SELECT * FROM `article` WHERE `id` = 484565 LIMIT 1 [ RunTime:0.000625s ]
  9. UPDATE `article` SET `lasttime` = 1776699367 WHERE `id` = 484565 [ RunTime:0.000450s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000249s ]
  11. SELECT * FROM `article` WHERE `id` < 484565 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.014071s ]
  12. SELECT * FROM `article` WHERE `id` > 484565 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000509s ]
  13. SELECT * FROM `article` WHERE `id` < 484565 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.007856s ]
  14. SELECT * FROM `article` WHERE `id` < 484565 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.018690s ]
  15. SELECT * FROM `article` WHERE `id` < 484565 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.013978s ]
0.130260s