建议收藏!献给Python初学者的22个入门小项目,练手必备!

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Python全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img



既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Python知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024c (备注Python)
img

正文

def clean(text): text = re.sub(r"[[0-9]*]“,” ",text)

text = text.lower() text = re.sub(r’\s+'," “,text) text = re.sub(r”,“,” ",text)

return text

summary = clean(summary)

print(“Getting the data…\n”)

##Tokenixing

sent_tokens = sent_tokenize(summary)

summary = re.sub(r"[^a-zA-z]“,” ",summary)

word_tokens = word_tokenize(summary)

Removing Stop words

word_frequency = {}stopwords = set(stopwords.words(“english”))

for word in word_tokens:

if word not in stopwords:

if word not in word_frequency.keys():

word_frequency[word]=1

else:

word_frequency[word] +=1

maximum_frequency = max(word_frequency.values())

print(maximum_frequency)

for word in word_frequency.keys():

word_frequency[word] = (word_frequency[word]/maximum_frequency)

print(word_frequency)

sentences_score = {}

for sentence in sent_tokens:

for word in word_tokenize(sentence):

if word in word_frequency.keys(): if (len(sentence.split(" "))) <30:

if sentence not in sentences_score.keys():

sentences_score[sentence] = word_frequency[word]

else:

sentences_score[sentence] += word_frequency[word]

print(max(sentences_score.values()))

def get_key(val):

for key, value in sentences_score.items():

if val == value:

return key

key = get_key(max(sentences_score.values()))print(key+“\n”)

print(sentences_score)

summary = heapq.nlargest(num,sentences_score,key=sentences_score.get)print(" ".join(summary))summary = " ".join(summary)

9、随机密码生成器

创建一个程序,可指定密码长度,生成一串随机密码。

创建一个数字+大写字母+小写字母+特殊字符的字符串。根据设定的密码长度随机生成一串密码。

import random

passlen = int(input(“enter the length of password”))

s="abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLNNOPQRSTUVWXYz!简#$x^6a()?p=.join(random.sample(s.passlen )

print§


enter the length of password6

za1gBe

10、闹钟

编写一个创建闹钟的Python脚本。

你可以使用date-time模块创建闹钟,以及playsound库播放声音。

from datetime import datetime

from playsound import playsound

alarm_time = input(“Enter the time of alarm to be set:HH:MM:SS\n”)

alarm_hour=alarm_time[0:2]

alarm_minute=alarm_time[3:5]

alarm_seconds=alarm_time[6:8]

alarm_period = alarm_time[9:11].upper()

print(“Setting up alarm…”)

while True:

now = datetime.now()

current_hour = now.strftime(“%I”)

current_minute = now.strftime(“%M”)

current_seconds = now.strftime(“%S”)

current_period = now.strftime(“%p”)

if(alarm_period==current_period):

if(alarm_hour==current_hour):

if(alarm_minute==current_minute):

if(alarm_seconds==current_seconds):

print(“Wake Up!”)

playsound(‘audio.mp3’) ## download the alarm sound from link

break

11、文字冒险游戏

编写一个有趣的Python脚本,通过为路径选择不同的选项让用户进行有趣的冒险。

name = str( input(“Enter Your Mame\n”))

print(f"{name} you are stuck in a forest.Your task is to get out from the forest withoutdieing")

print(“You are walking threw forest and suddenly a wolf comes in your way.Now Youoptions.”)

print("1.Run 2. climb The Nearest Tree ")

user = int(input(“choose one option 1 or 2”))

if user = 1:

print(“You Died!!”)

elif user = 2:

print(“You Survived!!”)

else:

print(“Incorrect Input”)

Add a loop and increase the story as much as you can

12、有声读物

编写一个Python脚本,用于将Pdf文件转换为有声读物。

借助pyttsx3库将文本转换为语音。

要安装的模块:

pyttsx3

PyPDF2

import pyttsx3,PyPDF2

DdfReader = pyPDF2.PdfFileReader(open( "file.pdf’,"rb’))

speaker = pyttsx3.init()

for page_num in range(pdfReader.numPages):

text =pdfReader.getPage(page_num).extractText()

speaker.say(text)

speaker.runAndwait()

speaker.stopo()

13、货币换算器

编写一个Python脚本,可以将一种货币转换为其他用户选择的货币。

使用Python中的API,或者通过forex-python模块来获取实时的货币汇率。

安装:forex-python

from forex _python.converter import CurrencyRatesc = CurrencyRates()

amount = int(input(“Enter The Amount You Want To Convert\n”))

from_currency = input( “From\n” )-upper()

to_currency = input( “To\n”).upper()

print(from_currency,“To”,to_currency , amount)

result = c.convert(from_currency, to_currency, amount)

print(result)

14、天气应用

编写一个Python脚本,接收城市名称并使用爬虫获取该城市的天气信息。

你可以使用Beautifulsoup和requests库直接从谷歌主页爬取数据。

安装:

requests

BeautifulSoup

from bs4 import BeautifulSoup

import requests

headers = {‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3’}

def weather(city):

city=city.replace(" “,”+")

res = requests.get(f’https://www.google.com/search?q={city}&oq={city}&aqs=chrome.0.35i39l2j0l4j46j69i60.6128j1j7&sourceid=chrome&ie=UTF-8’,headers=headers)

print(“Searching in google…\n”)

soup = BeautifulSoup(res.text,‘html.parser’)

location = soup.select(‘#wob_loc’)[0].getText().strip()

time = soup.select(‘#wob_dts’)[0].getText().strip()

info = soup.select(‘#wob_dc’)[0].getText().strip()

weather = soup.select(‘#wob_tm’)[0].getText().strip()

print(location)

print(time)

print(info)

print(weather+“°C”)

print(“enter the city name”)

city=input()

city=city+" weather"

weather(city)

15、人脸检测

编写一个Python脚本,可以检测图像中的人脸,并将所有的人脸保存在一个文件夹中。

可以使用haar级联分类器对人脸进行检测。它返回的人脸坐标信息,可以保存在一个文件中。

安装:

OpenCV

下载:haarcascade_frontalface_default.xml

import cv2

Load the cascade

face_cascade = cv2.CascadeClassifier(‘haarcascade_frontalface_default.xml’)

Read the input image

img = cv2.imread(‘images/img0.jpg’)

Convert into grayscale

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

Detect faces

faces = face_cascade.detectMultiScale(gray, 1.3, 4)

Draw rectangle around the faces

for (x, y, w, h) in faces:

cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)

crop_face = img[y:y + h, x:x + w]

cv2.imwrite(str(w) + str(h) + ‘_faces.jpg’, crop_face)

Display the output

cv2.imshow(‘img’, img)

cv2.imshow(“imgcropped”,crop_face)

cv2.waitKey()

16、提醒应用

创建一个提醒应用程序,在特定的时间提醒你做一些事情(桌面通知)。

Time模块可以用来跟踪提醒时间,toastnotifier库可以用来显示桌面通知。

安装:win10toast

from win10toast import ToastNotifier

import time

toaster = ToastNotifier()

try:

print(“Title of reminder”)

header = input()

print(“Message of reminder”)

text = input()

print(“In how many minutes?”)

time_min = input()

time_min=float(time_min)

except:

header = input(“Title of reminder\n”)

text = input(“Message of remindar\n”)

time_min=float(input(“In how many minutes?\n”))

time_min = time_min * 60

print(“Setting up reminder…”)

time.sleep(2)

print(“all set!”)

time.sleep(time_min)

toaster.show_toast(f"{header}",

f"{text}",

duration=10,

threaded=True)

while toaster.notification_active(): time.sleep(0.005)

17、Hangman

创建一个简单的命令行hangman游戏。

创建一个密码词的列表并随机选择一个单词。现在将每个单词用下划线“”表示,给用户提供猜单词的机会,如果用户猜对了单词,则将“”用单词替换。

import time

import random

name = input("What is your name? ")

print ("Hello, " + name, “Time to play hangman!”)

time.sleep(1)

print (“Start guessing…\n”)

time.sleep(0.5)

A List Of Secret Words

words = [‘python’,‘programming’,‘treasure’,‘creative’,‘medium’,‘horror’]

word = random.choice(words)

guesses = ‘’

turns = 5

while turns > 0:

failed = 0

for char in word:

if char in guesses:

print (char,end=“”)

else:

print (“_”,end=“”),

failed += 1

if failed == 0:

print (“\nYou won”)

break

guess = input(“\nguess a character:”)

guesses += guess

if guess not in word:

turns -= 1

print(“\nWrong”)

print(“\nYou have”, + turns, ‘more guesses’)

if turns == 0:

print (“\nYou Lose”)

18、文章朗读器

编写一个Python脚本,自动从提供的链接读取文章。

import pyttsx3

import requests

from bs4 import BeautifulSoup

url = str(input(“Paste article url\n”))

def content(url):

res = requests.get(url)

soup = BeautifulSoup(res.text,‘html.parser’)

articles = []

for i in range(len(soup.select(‘.p’))):

article = soup.select(‘.p’)[i].getText().strip()

articles.append(article)

contents = " ".join(articles)

return contents

engine = pyttsx3.init(‘sapi5’)

voices = engine.getProperty(‘voices’)

engine.setProperty(‘voice’, voices[0].id)

def speak(audio):

engine.say(audio)

engine.runAndWait()

contents = content(url)

print(contents) ## In case you want to see the content

#engine.save_to_file

#engine.runAndWait() ## In case if you want to save the article as a audio file

19、获取谷歌搜索结果

创建一个脚本,可以根据查询条件从谷歌搜索获取数据。

from bs4 import BeautifulSoup

import requests

headers = {‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3’}

def google(query):

query = query.replace(" “,”+")

try:

url = f’https://www.google.com/search?q={query}&oq={query}&aqs=chrome…69i57j46j69i59j35i39j0j46j0l2.4948j0j7&sourceid=chrome&ie=UTF-8’

res = requests.get(url,headers=headers)

soup = BeautifulSoup(res.text,‘html.parser’)

except:

print(“Make sure you have a internet connection”)

try:

try:

ans = soup.select(‘.RqBzHd’)[0].getText().strip()

except:

try:

title=soup.select(‘.AZCkJd’)[0].getText().strip()

try:

ans=soup.select(‘.e24Kjd’)[0].getText().strip()

except:

ans=“”

ans=f’{title}\n{ans}’

except:

try:

ans=soup.select(‘.hgKElc’)[0].getText().strip()

except:

ans=soup.select(‘.kno-rdesc span’)[0].getText().strip()

except:

ans = “can’t find on google”

return ans

result = google(str(input(“Query\n”)))

print(result)

获取结果如下

在这里插入图片描述

20、键盘记录器

编写一个Python脚本,将用户按下的所有键保存在一个文本文件中。

pynput是Python中的一个库,用于控制键盘和鼠标的移动,它也可以用于制作键盘记录器。简单地读取用户按下的键,并在一定数量的键后将它们保存在一个文本文件中。

from pynput.keyboard import Key, Controller,Listener

import time

keyboard = Controller()

keys=[]

def on_press(key):

global keys

#keys.append(str(key).replace(“'”,“”))

string = str(key).replace(“'”,“”)

keys.append(string)

main_string = “”.join(keys)

print(main_string)

if len(main_string)>15:

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注python)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

获取结果如下

在这里插入图片描述

20、键盘记录器

编写一个Python脚本,将用户按下的所有键保存在一个文本文件中。

pynput是Python中的一个库,用于控制键盘和鼠标的移动,它也可以用于制作键盘记录器。简单地读取用户按下的键,并在一定数量的键后将它们保存在一个文本文件中。

from pynput.keyboard import Key, Controller,Listener

import time

keyboard = Controller()

keys=[]

def on_press(key):

global keys

#keys.append(str(key).replace(“'”,“”))

string = str(key).replace(“'”,“”)

keys.append(string)

main_string = “”.join(keys)

print(main_string)

if len(main_string)>15:

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注python)
[外链图片转存中…(img-CsWEvC4H-1713586141096)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值