20253201刘人宁实验四实验报告

20253201 2025-2026-2 《Python程序设计》实验四报告
课程名称: Python程序设计
实验项目: 综合实践——天气推送程序
姓 名: 刘人宁
学 号: 20253201
班 级: 2532
实验日期: 2026年5月12日

一、实验基本信息

1.实验名称:基于 Python 实现天气数据爬取与企业微信定时推送
2.实验目的:综合运用这学期所学的python技术,实现每日定点天气微信提醒
3.实验环境:Python、Windows 系统

二、实验原理

利用 requests 库请求天气网站页面,BeautifulSoup 解析网页源码提取气温、天气状况、风力等数据
调用企业微信机器人 Webhook 接口,以 JSON 格式提交文本消息完成群内推送
借助多线程循环判断系统时间,到达设定时刻自动执行爬取与推送任务

三、实验过程与尝试方案

1.首先实现爬取天气信息的功能
image
2.然后问问豆包怎么实现微信推送

0c3fd8f1855713b03ff87d66e892d99f

(1)由于方案一比较简单,所以先采用方案一试试
然而
e153c938ea7e638dd9079895c771d94d
问问豆包为什么?
c9e57f5934e893061a6a487ebcb70623
我直接用最简单最直白最不绕弯子的话告诉你,包姐骗你的,早就用不了了,还给你说声对不起。
(2)再试试方案二用企业微信机器人来实现,再一遍遍看视频问豆包之后终于实现了再企业微信的群聊推送,但是却怎么也实现不了绑定微信,才发现这个功能已经被更新砍了,现在要申请企业认证才能用。豆包:别往心里去,豆姐跟你开玩笑呢。
代码如下:

点击查看代码
import requests
from bs4 import BeautifulSoup
import time
import threading
from datetime import datetime

city_id = "101030100"
send_h = 7
send_m = 30
wx_url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=b0463bf2-34bc-4276-ac1f-ebe5d39a5490"


def get_weather(cityid):
    web_url = "http://www.weather.com.cn/weather/" + cityid + ".shtml"
    header = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/130.0.0.0 Safari/537.36"
    }
    try:
        page = requests.get(web_url, headers=header, timeout=10)
        page.encoding = "utf-8"
        html = BeautifulSoup(page.text, "html.parser")

        city_name = html.find("h1").get_text(strip=True)
        today_data = html.find("ul", class_="t clearfix").find("li")
        weather_text = today_data.find("p", class_="wea").get_text(strip=True)
        temperature = today_data.find("p", class_="tem").get_text(strip=True)
        wind_level = today_data.find("p", class_="win").get_text(strip=True)

        msg = city_name + " 今日天气提醒\n"
        msg = msg + "天气:" + weather_text + "\n"
        msg = msg + "温度:" + temperature + "\n"
        msg = msg + "风力:" + wind_level + "\n"

        if "雨" in weather_text:
            msg = msg + "\n有雨,记得带伞"
        elif "雪" in weather_text:
            msg = msg + "\n路面湿滑,注意保暖"
        else:
            num_temp = temperature.replace("℃", "")
            num_temp = num_temp.replace(" ", "")
            if "-" in num_temp:
                low_num = int(num_temp.split("-")[0])
                if low_num < 5:
                    msg = msg + "\n气温偏低,多穿衣服"
            else:
                if int(num_temp) > 30:
                    msg = msg + "\n天气炎热,注意防暑"
        return msg
    except:
        return "天气数据获取失败"


def send_wechat(content):
    send_data = {
        "msgtype": "text",
        "text": {"content": content}
    }
    try:
        back = requests.post(wx_url, json=send_data, timeout=10)
        back_json = back.json()
        if back.status_code == 200 and back_json["errcode"] == 0:
            print("消息发送成功")
            return 1
        else:
            print("消息发送失败")
            return 0
    except:
        print("发送出错啦")
        return 0


def time_work():
    print("定时任务已经启动")
    while 1:
        now = datetime.now()
        if now.hour == send_h and now.minute == send_m:
            weather_info = get_weather(city_id)
            send_wechat(weather_info)
            time.sleep(60)
        time.sleep(10)
print("程序启动,开始获取天气")
info = get_weather(city_id)
send_wechat(info)

new_thread = threading.Thread(target=time_work)
new_thread.daemon = True
new_thread.start()

while 1:
    time.sleep(1)

效果如下:

image

关于同步微信我尝试了两种方法,一种是关联使微信可以接受企业微信消息,发现这个功能已经被更新砍了,现在要申请企业认证才能用。第二种是以企业微信建群,拉入微信用户,发现这种外部群聊根本无法添加机器人。
image
于是,这种方案基本实现了推送,但效果差强人意,毕竟谁会天天看企业微信,不方便还占用手机空间。
(3)最终我尝试了方案三
通过sever酱第三方微信推送工具,只需要简单登入sever酱获取key就可以实现微信服务号推送,肥肠方便(๑•̀ㅂ•́)و✧。
代码如下

点击查看代码
import requests
from bs4 import BeautifulSoup
import time
import threading
from datetime import datetime

city_code = "101030100"  # 天津城市代码
send_key = "SCT358016T0bOEqhCpGlIWHrg5F61pATHd  "
hour =22   # 推送小时
minute = 13 # 推送分钟

def get_tianqi():
    url = "http://www.weather.com.cn/weather/" + city_code + ".shtml"
    header = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/130.0.0"
    }
    try:
        res = requests.get(url, headers=header, timeout=10)
        res.encoding = "utf-8"
        soup = BeautifulSoup(res.text, "html.parser")

        city_name = soup.find("h1").text.strip()
        today = soup.find("ul", class_="t clearfix").find("li")
        tq = today.find("p", class_="wea").text.strip()
        wd = today.find("p", class_="tem").text.strip()
        fl = today.find("p", class_="win").text.strip()

        tip = ""
        if "雨" in tq:
            tip = "下雨啦,记得带伞"
        elif "雪" in tq:
            tip = "下雪路滑,注意保暖"
        else:
            num = wd.replace("℃", "").replace(" ", "")
            if "-" in num:
                low = int(num.split("-")[0])
                if low < 5:
                    tip = "气温偏低,多穿衣服"
            else:
                if int(num) > 30:
                    tip = "天气炎热,注意防暑"

        msg = city_name + " 今日天气\n"
        msg = msg + "天气:" + tq + "\n"
        msg = msg + "温度:" + wd + "\n"
        msg = msg + "风力:" + fl + "\n"
        msg = msg + tip

        return msg
    except:
        return "天气获取失败"

def send_wx():
    content = get_tianqi()
    url = "https://sctapi.ftqq.com/" + send_key + ".send"
    data = {
        "title": "每日天气提醒",
        "desp": content
    }
    try:
        requests.post(url, data=data)
        print("消息发送成功")
    except:
        print("消息发送失败")

def ding_shi():
    print("定时任务已启动")
    while 1:
        now = datetime.now()
        if now.hour == hour and now.minute == minute:
            send_wx()
            time.sleep(60)
        time.sleep(10)

if __name__ == "__main__":
    print("正在测试发送消息...")
    send_wx()
    t = threading.Thread(target=ding_shi)
    t.start()

    while 1:
        time.sleep(1)

效果如下
4ac8398befaaa91824394c5a8df95ff0
0ca3ef21404c55c5e02ca0d2acfbcca0

基本功能已经实现,现在进行一些创新,加一些有意思的东西

1.自己穿衣服容易只顾好看而不管薄厚冷暖,季节变换也容易不知道盖什么被子,所以加一个衣物被子推荐功能。
2.加一个跑操预测功能
先把最近不跑操的记录丢给豆包,让他查一下当日天气,拟合一下推导出一个跑操概率公式。但后面发现,跑操不只和当日有关,于是又加上前一天的天气,而且不同天气的权重也不应该一样,比如前日下雪肯定要比前日下雨对跑操的影响大,于是加入前日天气和权重。发现还是不准确,检查后发现是,当日天气算入了下午的天气,但是跑操在上午,下午天气不会影响,所以改正为前天全天天气+当日上午天气。
1bca61a7a4cd024fac724d1e1674f17b
9fdb15f9223eb2e7403f763b691c0e01

最终效果如下

54759633f085e28d82576094a81bba52

代码如下

点击查看代码
import requests
from bs4 import BeautifulSoup
import time
import threading
from datetime import datetime

city_code = "101030100"  #城市代码
send_key = "SCT358016T0bOEqhCpGlIWHrg5F61pATHd  "
hour = 22   #推送小时
minute = 13 #推送分钟

def get_tianqi():
    url = "http://www.weather.com.cn/weather/" + city_code + ".shtml"
    header = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/130.0.0"
    }
    try:
        res = requests.get(url, headers=header, timeout=10)
        res.encoding = "utf-8"
        soup = BeautifulSoup(res.text, "html.parser")

        city_name = soup.find("h1").text.strip()
        today = soup.find("ul", class_="t clearfix").find("li")
        tq = today.find("p", class_="wea").text.strip()
        wd = today.find("p", class_="tem").text.strip()
        fl = today.find("p", class_="win").text.strip()

        tip = ""
        if "雨" in tq:
            tip = "下雨啦,记得带伞"
        elif "雪" in tq:
            tip = "下雪路滑,注意保暖"
        else:
            num = wd.replace("℃", "").replace(" ", "")
            if "-" in num:
                low = int(num.split("-")[0])
                if low < 5:
                    tip = "气温偏低,多穿衣服"
            else:
                if int(num) > 30:
                    tip = "天气炎热,注意防暑"
        msg = city_name + " 今日天气\n"
        msg = msg + "天气:" + tq + "\n"
        msg = msg + "温度:" + wd + "\n"
        msg = msg + "风力:" + fl + "\n"
        msg = msg + tip

        return msg, tq, wd
    except:
        return "天气获取失败", "未知天气", "未知温度"

def get_clothes_bedtip(temp_str):
    num_raw = temp_str.replace("℃", "").replace(" ", "")
    low_temp = 15
    try:
        if "/" in num_raw:
            low_temp = int(num_raw.split("/")[-1])
        elif "~" in num_raw:
            low_temp = int(num_raw.split("~")[0])
        elif "-" in num_raw and not num_raw.startswith("-"):
            low_temp = int(num_raw.split("-")[0])
        else:
            low_temp = int(num_raw)
    except:
        low_temp = 15

    if low_temp <= 5:
        clothes = "穿搭:厚羽绒服、加绒秋衣秋裤、棉裤、保暖鞋,防风围巾"
        bed = "被褥:厚棉被+毛毯,夜间注意关好门窗防寒"
    elif 5 < low_temp <= 15:
        clothes = "穿搭:薄羽绒服/呢子大衣、长袖打底+薄长裤"
        bed = "被褥:常规加厚棉被即可"
    elif 15 < low_temp <= 25:
        clothes = "穿搭:薄外套、长袖T恤/薄卫衣、休闲长裤"
        bed = "被褥:春秋薄被,无需厚被"
    else:
        clothes = "穿搭:短袖、短裤/薄长裤,透气面料"
        bed = "被褥:夏凉被,夜间注意空调别着凉"
    return f"\n【穿搭&被褥提示】\n{clothes}\n{bed}"
def calc_A(weather):
    if "大雪" in weather:
        return 1.00
    elif "大雨" in weather:
        return 0.90
    elif "小雪" in weather:
        return 0.70
    elif "小雨" in weather:
        return 0.50
    elif any(k in weather for k in ["雾", "霾", "沙尘"]):
        return 0.40
    else:
        return 0.00

# B系数(前一日全天天气)
def calc_B(pre_weather):
    if "大雪" in pre_weather:
        return 1.00
    elif "大雨" in pre_weather:
        return 0.80
    elif "小雪" in pre_weather:
        return 0.50
    elif "小雨" in pre_weather:
        return 0.30
    else:
        return 0.00

def get_run_prob(day_week, now_weather, pre_day_weather):
    if day_week in [5, 6]:
        return 0.0
    A = calc_A(now_weather)
    B = calc_B(pre_day_weather)
    P = (1 - A) * (1 - B) * 100
    return round(P, 2)

def get_7day_run_forecast():
    url = "http://www.weather.com.cn/weather/" + city_code + ".shtml"
    header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/130.0.0"}
    try:
        res = requests.get(url, headers=header, timeout=10)
        res.encoding = "utf-8"
        soup = BeautifulSoup(res.text, "html.parser")
        day_list = soup.select("ul.t.clearfix > li")
        weather_arr = []
        week_arr = []
        for li in day_list[:7]:
            wk_text = li.find("h1").text.strip()
            w_text = li.find("p", class_="wea").text.strip()

            if "雷阵雨" in w_text or "阵雨" in w_text:
                w_text = "小雨"
            week_arr.append(wk_text)
            weather_arr.append(w_text)

        forecast_text = "\n【未来7天跑操概率预测】\n"
        today_wk = datetime.now().weekday()
        for i in range(7):
            curr_wk = (today_wk + i) % 7
            curr_wea = weather_arr[i]
            if i == 0:
                pre_wea = "晴"
            else:
                pre_wea = weather_arr[i-1]
            prob = get_run_prob(curr_wk, curr_wea, pre_wea)
            forecast_text += f"{week_arr[i]}:{prob}%概率正常跑操\n"
        return forecast_text
    except Exception as e:
        return f"\n【未来7天跑操概率预测】\n7天天气数据获取失败:{str(e)}"

def send_wx():
    content, today_wea, today_temp = get_tianqi()
    add_cloth = get_clothes_bedtip(today_temp)
    add_run = get_7day_run_forecast()
    full_msg = content + add_cloth + add_run

    url = "https://sctapi.ftqq.com/" + send_key + ".send"
    data = {
        "title": "每日天气提醒",
        "desp": full_msg
    }
    try:
        requests.post(url, data=data)
        print("消息发送成功")
    except:
        print("消息发送失败")

def ding_shi():
    print("定时任务已启动")
    while 1:
        now = datetime.now()
        if now.hour == hour and now.minute == minute:
            send_wx()
            time.sleep(60)
        time.sleep(10)

if __name__ == "__main__":
    print("正在测试发送消息...")
    send_wx()
    t = threading.Thread(target=ding_shi)
    t.start()
    while 1:
        time.sleep(1)

最后让ai美化一下写个GUI。

效果如下
c2707dc75debefc77e5783d8bb6e300c
0d2d53de1afc2f706f5bea0c80dd3bad
代码如下

点击查看代码
import requests
from bs4 import BeautifulSoup
import time
import threading
from datetime import datetime
import tkinter as tk
from tkinter import ttk


city_code = "101030100"
send_key = "SCT358016T0bOEqhCpGlIWHrg5F61pATHd"
push_hour = 22
push_minute = 13


def get_tianqi():
    url = "http://www.weather.com.cn/weather/" + city_code + ".shtml"
    header = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/130.0.0"
    }
    try:
        res = requests.get(url, headers=header, timeout=10)
        res.encoding = "utf-8"
        soup = BeautifulSoup(res.text, "html.parser")

        city_name = soup.find("h1").text.strip()
        today = soup.find("ul", class_="t clearfix").find("li")
        tq = today.find("p", class_="wea").text.strip()
        wd = today.find("p", class_="tem").text.strip()
        fl = today.find("p", class_="win").text.strip()

        tip = ""
        if "雨" in tq:
            tip = "下雨啦,记得带伞"
        elif "雪" in tq:
            tip = "下雪路滑,注意保暖"
        else:
            num = wd.replace("℃", "").replace(" ", "")
            if "-" in num:
                low = int(num.split("-")[0])
                if low < 5:
                    tip = "气温偏低,多穿衣服"
            else:
                if int(num) > 30:
                    tip = "天气炎热,注意防暑"

        msg = f"### {city_name} 今日天气\n\n"
        msg += f"- 天气:{tq}\n"
        msg += f"- 温度:{wd}\n"
        msg += f"- 风力:{fl}\n"
        msg += f"- 温馨提示:{tip}\n"
        return msg, tq, wd
    except:
        return "### 天气获取失败", "未知天气", "未知温度"


def get_clothes_bedtip(temp_str):
    num_raw = temp_str.replace("℃", "").replace(" ", "")
    low_temp = 15
    try:
        if "/" in num_raw:
            low_temp = int(num_raw.split("/")[-1])
        elif "~" in num_raw:
            low_temp = int(num_raw.split("~")[0])
        elif "-" in num_raw and not num_raw.startswith("-"):
            low_temp = int(num_raw.split("-")[0])
        else:
            low_temp = int(num_raw)
    except:
        low_temp = 15
    if low_temp <= 5:
        clothes = "厚羽绒服、加绒秋衣秋裤、棉裤、保暖鞋,防风围巾"
        bed = "厚棉被+毛毯,夜间注意关好门窗防寒"
    elif 5 < low_temp <= 15:
        clothes = "薄羽绒服/呢子大衣、长袖打底+薄长裤"
        bed = "常规加厚棉被即可"
    elif 15 < low_temp <= 25:
        clothes = "薄外套、长袖T恤/薄卫衣、休闲长裤"
        bed = "春秋薄被,无需厚被"
    else:
        clothes = "短袖、短裤/薄长裤,透气面料"
        bed = "夏凉被,夜间注意空调别着凉"

    res = "\n---\n### 👕穿搭&被褥提示\n\n"
    res += f"- 穿搭建议:{clothes}\n"
    res += f"- 被褥建议:{bed}\n"
    return res

# A/B系数、跑操概率
def calc_A(weather):
    if "大雪" in weather:
        return 1.00
    elif "大雨" in weather:
        return 0.90
    elif "小雪" in weather:
        return 0.70
    elif "小雨" in weather:
        return 0.50
    elif any(k in weather for k in ["雾", "霾", "沙尘"]):
        return 0.40
    else:
        return 0.00

def calc_B(pre_weather):
    if "大雪" in pre_weather:
        return 1.00
    elif "大雨" in pre_weather:
        return 0.80
    elif "小雪" in pre_weather:
        return 0.50
    elif "小雨" in pre_weather:
        return 0.30
    else:
        return 0.00

def get_run_prob(day_week, now_weather, pre_day_weather):
    if day_week in [5, 6]:
        return 0.0
    A = calc_A(now_weather)
    B = calc_B(pre_day_weather)
    P = (1 - A) * (1 - B) * 100
    return round(P, 2)

def get_7day_run_forecast():
    url = "http://www.weather.com.cn/weather/" + city_code + ".shtml"
    header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/130.0.0"}
    try:
        res = requests.get(url, headers=header, timeout=10)
        res.encoding = "utf-8"
        soup = BeautifulSoup(res.text, "html.parser")
        day_list = soup.select("ul.t.clearfix > li")
        weather_arr = []
        week_arr = []
        for li in day_list[:7]:
            wk_text = li.find("h1").text.strip()
            w_text = li.find("p", class_="wea").text.strip()
            if "雷阵雨" in w_text or "阵雨" in w_text:
                w_text = "小雨"
            week_arr.append(wk_text)
            weather_arr.append(w_text)

        forecast_text = "\n---\n### 🏃未来7天跑操概率预测\n\n"
        today_wk = datetime.now().weekday()
        for i in range(7):
            curr_wk = (today_wk + i) % 7
            curr_wea = weather_arr[i]
            pre_wea = weather_arr[i-1] if i>0 else "晴"
            prob = get_run_prob(curr_wk, curr_wea, pre_wea)
            forecast_text += f"- {week_arr[i]}:{prob}%概率正常跑操\n"
        return forecast_text
    except Exception as e:
        return f"\n---\n### 🏃未来7天跑操概率预测\n\n数据获取失败:{str(e)}"

def send_wx():
    global send_key
    content, today_wea, today_temp = get_tianqi()
    add_cloth = get_clothes_bedtip(today_temp)
    add_run = get_7day_run_forecast()
    full_msg = content + add_cloth + add_run
    url = "https://sctapi.ftqq.com/" + send_key.strip() + ".send"
    data = {"title": "每日天气&跑操提醒", "desp": full_msg}
    try:
        requests.post(url, data=data)
        return "✅消息发送成功"
    except Exception as e:
        return f"❌发送失败:{str(e)}"

def ding_shi():
    global push_hour,push_minute
    while True:
        now = datetime.now()
        if now.hour == push_hour and now.minute == push_minute:
            send_wx()
            time.sleep(60)
        time.sleep(10)

# ==========GUI界面==========
root = tk.Tk()
root.title("天气推送配置工具|美化排版版")
root.geometry("500x360")


var_city = tk.StringVar(value=city_code)
var_sckey = tk.StringVar(value=send_key.strip())
var_h = tk.StringVar(value=str(push_hour))
var_m = tk.StringVar(value=str(push_minute))
var_log = tk.StringVar(value="就绪,修改参数后点保存配置")


def save_config():
    global city_code,send_key,push_hour,push_minute
    city_code = var_city.get().strip()
    send_key = var_sckey.get().strip()
    try:
        push_hour = int(var_h.get())
        push_minute = int(var_m.get())
        var_log.set("✅配置保存完成")
    except:
        var_log.set("❌时分必须是数字")


def test_send():
    res = send_wx()
    var_log.set(res)


def start_task():
    t = threading.Thread(target=ding_shi, daemon=True)
    t.start()
    var_log.set("⏰定时任务已后台启动")


ttk.Label(root,text="城市天气代码:").place(x=30,y=25)
ent_city = ttk.Entry(root,textvariable=var_city,width=42)
ent_city.place(x=130,y=25)

ttk.Label(root,text="Server酱SCKEY:").place(x=30,y=65)
ent_key = ttk.Entry(root,textvariable=var_sckey,width=42)
ent_key.place(x=130,y=65)

ttk.Label(root,text="推送定时:").place(x=30,y=105)
ent_h = ttk.Entry(root,textvariable=var_h,width=6)
ent_h.place(x=130,y=105)
ttk.Label(root,text="时").place(x=175,y=105)
ent_m = ttk.Entry(root,textvariable=var_m,width=6)
ent_m.place(x=205,y=105)
ttk.Label(root,text="分").place(x=250,y=105)


btn_save = ttk.Button(root,text="保存配置",command=save_config)
btn_save.place(x=30,y=150,width=110)
btn_test = ttk.Button(root,text="测试推送",command=test_send)
btn_test.place(x=155,y=150,width=110)
btn_start = ttk.Button(root,text="启动定时",command=start_task)
btn_start.place(x=280,y=150,width=110)


ttk.Label(root,text="运行日志:").place(x=30,y=200)
lab_log = ttk.Label(root,textvariable=var_log,foreground="#227722")
lab_log.place(x=90,y=200)

root.mainloop()

四、实验问题、故障分析与解决。

1.前两个个微信推送方案不能用
原因:方法太老,所用功能已经更新失效
解决:换了一个方法
2.在加入新功能后,推送消息一直显示为“天气获取失败”
原因:在加入新功能时,不小心写了一个错误的逻辑,导致一些代码必定执行,效果是推送发生错误的原因 “天气获取失败”并结束代码。
解决:更正错误逻辑
3.利用ai美化并添加GUI时,代码报错
原因:豆包瞎写
解决:让他重新写
4.跑操概率公式预测不准
原因:漏掉了好多因素
解决:加入前日天气,当天天气改为上午,加入天气权重

五、实验结果

成功爬取目标城市实时天气、温度、风力信息,并附带衣物被子雨伞提示,并成功预测跑操,经检验第二天跑操预测准确率高达90%(低于50%算预测不跑操,反之亦然,10天猜对了9天,有一天没猜对,因为那天其实应该跑操的,早上没雨,但是不知道为啥没跑操。)定时功能生效。

六、视频演示

七、Gitee链接

gitee链接

八、实验总结与体会

这次期末大作业,让我明白,一个程序的开发是多么费劲,一个程序不同于平时的作业,代码量一上来,写完直接十几个报错,而且改一个多出来两个,非常折磨。同时我也认识到大模型的局限性,在利用ai美化添加GUI时它写的代码全是错,而且根本没法改,只能让它重新做,并不像平时用它生成个论文呢一样,发个要求就行,项目难度一上来,要求一复杂,它就像听不懂人话一样,要反复修改提示词,反复尝试,耗费的时间都足够自己完成任务了。这提醒我,不能过于依赖大模型,自己会永远强于大模型,运用更灵活,并且自己会的话即使运用大模型也更加得心应手。

九、课程感悟与体会

通过本次课程,我在老师的带领下逐步从python门外汉成长为具备基本编程能力的python小白,从配置pycharm,配置gitee,调试开始,逐步学习了变量,数据类型,运算和各种程序结构,然后学习了列表字符串元组等,最后学习了爬虫,实现了python从入门到入狱。并在最后的期末大作业中,运用了这些技巧,完成了一个基础的小程序。这一简单的程序,看似轻而易举,但是展现着我这一学期的进步,从开始的gitee都用不明白,到可以自己独立写程序,这一课程对我以后的学习也意义重大,感谢王老师的悉心教导。python之外我也感受到王老师并不是一个枯燥的人,反而呢十分有趣,从有意思的手势签到,到授课方式,再到群聊里面的发言、朋友圈。并且王老师十分耐心,第一次配置pycharm,王老师一直在教室调试同学设备到了10点。同时我发现王老师也十分热爱体育。对于课程的建议,我觉得就是关于python,gitee的配置一定要十分十分十分详细,因为这俩东西没配置好实在是太折磨了,还有就是王老师球踢的挺好,建议王老师多跟我们踢球。:-)

十、课程知识点总结

本学期Python课程内容循序渐进,我从零基础逐步掌握了Python的基础语法与常用编程方法。首先熟悉了变量、数据类型、运算符等基础内容,能够熟练使用顺序、分支、循环三种程序结构编写基础代码,掌握了break、continue等循环控制方式。
在数据结构方面,我学会了列表、字符串、元组、字典的日常使用,掌握了序列切片、数据遍历、增删改查等常用操作,理解了不同容器的特点和适用场景,尤其熟悉字典键值映射的使用方法,能够用它简化复杂判断逻辑。
同时我掌握了函数的定义与调用,理解了局部变量与全局变量的区别,学会将重复代码封装成函数,提高代码复用性。通过学习面向对象基础,我初步了解了类、对象、属性、方法以及简单的类继承,对模块化编程有了更直观的认识。
此外,我掌握了文件读写操作和异常捕获机制,能够通过try-except处理程序运行中的常见错误,有效提高程序稳定性。课程后期我还接触了第三方库使用、简单网络知识以及代码规范、程序调试方法,初步具备了独立编写、调试、完善小型Python项目的能力。

posted @ 2026-06-06 12:40  十人  阅读(16)  评论(1)    收藏  举报