Fundamentals 9 min read

7 Exciting Python Projects to Boost Your Coding Skills

This article presents seven practical Python projects—including a Zhihu image scraper, dual chatbot conversation, AI poetry author classifier, 35‑choose‑7 lottery generator, automatic apology letter writer, screen‑capture tool, and GIF creator—complete with ready‑to‑run code snippets and step‑by‑step explanations for developers eager to expand their programming repertoire.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
7 Exciting Python Projects to Boost Your Coding Skills

1. Zhihu Image Scraper

This script uses selenium to open a Zhihu question page, scroll to load content, extract image URLs with regular expressions, and download the first ten images.

import re
from selenium import webdriver
import time
import urllib.request

driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.zhihu.com/question/29134042")
for i in range(10):
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    time.sleep(2)
    try:
        driver.find_element_by_css_selector('button.QuestionMainAction').click()
        print("page" + str(i))
        time.sleep(1)
    except:
        break
    result_raw = driver.page_source
    content_list = re.findall("img src=\"(.+?)\" ", str(result_raw))
    n = 0
    while n < len(content_list):
        local = r"%s.jpg" % i
        urllib.request.urlretrieve(content_list[n], local)
        print("编号:" + str(i))
        n += 1

2. Dual Chatbot Conversation

The program lets a user input a topic, then alternates between the Turing API and the Qingyunke API to simulate two chatbots chatting with each other.

from time import sleep
import requests

s = input("请主人输入话题:")
while True:
    resp = requests.post("http://www.tuling123.com/openapi/api", data={"key":"4fede3c4384846b9a7d0456a5e1e2943","info":s})
    resp = resp.json()
    sleep(1)
    print('小鱼:', resp['text'])
    s = resp['text']
    resp = requests.get("http://api.qingyunke.com/api.php", params={"key":"free","appid":0,"msg":s})
    resp.encoding = 'utf8'
    resp = resp.json()
    sleep(1)
    print('菲菲:', resp['content'])

3. AI Poetry Author Classification

Using jieba for Chinese word segmentation and NLTK's Naive Bayes classifier, the script determines whether a given poem is more likely written by Li Bai or Du Fu.

import jieba
from nltk.classify import NaiveBayesClassifier

# Load poems
text1 = open(r"libai.txt", "rb").read()
list1 = jieba.cut(text1)
text2 = open(r"dufu.txt", "rb").read()
list2 = jieba.cut(text2)

# Feature extraction
def word_feats(words):
    return dict((word, True) for word in words)

libai_features = [(word_feats(lb), 'lb') for lb in list1]
dufu_features = [(word_feats(df), 'df') for df in list2]
train_set = libai_features + dufu_features
classifier = NaiveBayesClassifier.train(train_set)

sentence = input("请输入一句你喜欢的诗:")
seg_list = jieba.cut(sentence)
words = " ".join(seg_list).split()
lb = df = 0
for word in words:
    classResult = classifier.classify(word_feats(word))
    if classResult == 'lb':
        lb += 1
    if classResult == 'df':
        df += 1
x = float(lb) / len(words)
y = float(df) / len(words)
print('李白的可能性:%.2f%%' % (x * 100))
print('杜甫的可能性:%.2f%%' % (y * 100))

4. 35‑Choose‑7 Lottery Generator

Randomly shuffles numbers 1‑35 and selects the first seven as a lottery ticket.

import random

temp = [i + 1 for i in range(35)]
random.shuffle(temp)
list = []
for i in range(7):
    list.append(temp[i])
list.sort()
print('\033[0;31;;1m')
print(*list[0:6], end="")
print('\033[0;34;;1m', end=" ")
print(list[-1])

5. Automatic Apology Letter Generator

Combines user‑provided event description and required length to produce a formatted apology letter using random sentence lengths from an Excel sheet.

import random, xlrd
ExcelFile = xlrd.open_workbook(r'test.xlsx')
sheet = ExcelFile.sheet_by_name('Sheet1')
# ... (code to build the letter based on user input) ...

6. Screen Capture Tool

Captures screenshots at a user‑defined interval using PIL.ImageGrab and saves them as sequential JPEG files.

from time import sleep
from PIL import ImageGrab

m = int(input("请输入想抓屏几分钟:")) * 60
n = 1
while n < m:
    sleep(0.02)
    im = ImageGrab.grab()
    local = r"%s.jpg" % n
    im.save(local, 'jpeg')
    n += 1

7. GIF Creator

Opens a series of images and saves them as an animated GIF.

from PIL import Image
im = Image.open("1.jpg")
images = [Image.open('2.jpg'), Image.open('3.jpg')]
im.save('gif.gif', save_all=True, append_images=images, loop=1, duration=1, comment=b"aaabb")

These seven ready‑to‑run Python scripts demonstrate practical automation, data processing, and simple AI techniques that can be directly applied or extended for personal projects.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonAIChatbotdata-analysisrandom numberweb-scrapinggif-creation
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.