2024年Python最新建议收藏!献给Python初学者的22个入门小项目,练手必备!,腾讯面试经验汇总

最后

不知道你们用的什么环境,我一般都是用的Python3.6环境和pycharm解释器,没有软件,或者没有资料,没人解答问题,都可以免费领取(包括今天的代码),过几天我还会做个视频教程出来,有需要也可以领取~

给大家准备的学习资料包括但不限于:

Python 环境、pycharm编辑器/永久激活/翻译插件

python 零基础视频教程

Python 界面开发实战教程

Python 爬虫实战教程

Python 数据分析实战教程

python 游戏开发实战教程

Python 电子书100本

Python 学习路线规划

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

需要这份系统化学习资料的朋友,可以戳这里获取

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

兄弟们学习python,有时候不知道怎么学,从哪里开始学。掌握了基本的一些语法或者做了两个案例后,不知道下一步怎么走,不知道如何去学习更加高深的知识。

那么对于这些大兄弟们,我准备了大量的免费视频教程,PDF电子书籍,以及视频源的源代码!

还会有大佬解答!

都在这个群里了 点这里立即进裙

欢迎加入,一起讨论 一起学习!

2、故事生成器

每次用户运行程序时,都会生成一个随机的故事。

random模块可以用来选择故事的随机部分,内容来自每个列表里。

import random

when=[‘A few years ago’, ‘Yesterday’, ‘Last night’, ‘A long time ago’ , ‘On 20th Jan’]

who=[‘a rabbit’,‘an elephant’, ‘a mouse’, ‘a turtle’, ‘a cat’]

name=[ ‘Ali ‘,"Miriam’ , "danicL’,'Hoouk",‘Starwalker’1

residence-[ ‘Barcelona’ , " India’,‘Germany’,‘Venice’, ‘England’]

went= [ ‘cinema’,"university’ , ’ seminar’, ‘school’,'laundry ']

happened =[‘made a lot of friends’ , ‘Eats a burger’,‘found a secret key’, ’ solved a mistery’," wrote a book"]

print( random.choice(when) + ‘,’ +random.choice(who) + ’ that lived in ’ +

random.choice(residence) +', went to the ’ + random.choice(went) + ’ and ’ +

random.choice(happened))

-----------------------------------------OUTPUT-----------------------------------------

A long time ago, a cat that lived in England, went to the seminar and solved a mistery

3、邮件地址切片器

编写一个Python脚本,可以从邮件地址中获取用户名和域名。

使用@作为分隔符,将地址分为分为两个字符串。

#Get the user 's email address

email = input("what is your email address ?: ").strip()

Slice out the user name

email = input("what is your email address ?: ").strip()

Slice out the user name

domain_name = email[email.index(“a”)+1:]

#Format message

res = f"Your username is '{user_name}’ and your domain name is '{domain_name}"

Display the result message

print(res)

--------------------------------OUTPUT------------------------------------------

what is your email address?: karl31agmail.com

Your username is “karl31” and your domain name is 'gmail.com

4、句子生成器

通过用户提供的输入,来生成随机且唯一的句子。

以用户输入的名词、代词、形容词等作为输入,然后将所有数据添加到句子中,并将其组合返回。

color = input("Enter a color:“)

pluralNoun= input("Enter a plural noun: ")

celebrity input("Enter a celebrity: ")

print(“Roses are” ,color)

print(pluralNoun+ " are blue")

print(I love" , celebrity)


Red

Teeth

RDJ

Roses are red. teeth are blue. I Love RDJ

5、自动发送邮件

编写一个Python脚本,可以使用这个脚本发送电子邮件。

email库可用于发送电子邮件。

import smtplib

from email.message import EmailMessage

email = EmailMessage() ## Creating a object for EmailMessage

email[‘from’] = ‘xyz name’ ## Person who is sending

email[‘to’] = ‘xyz id’ ## Whom we are sending

email[‘subject’] = ‘xyz subject’ ## Subject of email

email.set_content(“Xyz content of email”) ## content of email

with smtlib.SMTP(host=‘smtp.gmail.com’,port=587)as smtp:

sending request to server

smtp.ehlo() ## server object

smtp.starttls() ## used to send data between server and client

smtp.login(“email_id”,“Password”) ## login id and password of gmail

smtp.send_message(email) ## Sending email

print(“email send”) ## Printing success message

6、猜数字游戏

在这个游戏中,任务是创建一个脚本,能够在一个范围内生成一个随机数。如果用户在三次机会中猜对了数字,那么用户赢得游戏,否则用户输。

生成一个随机数,然后使用循环给用户三次猜测机会,根据用户的猜测打印最终的结果。

import random

nunber = random.randint(1,10)

for i in range(e,3):

user =int(input(“guess the number”))

if user -number:

print(“Hurray H”)

print(f"you guessed the number right it’s {number}")

break

elif user>number:

print(“Your guess is too high”)

elif userenuimber:

print(Your guess is too low.")

else:

print(f"Nice Try!,but the number is {number}")

7、石头剪刀布游戏

创建一个命令行游戏,游戏者可以在石头、剪刀和布之间进行选择,与计算机PK。如果游戏者赢了,得分就会添加,直到结束游戏时,最终的分数会展示给游戏者。

接收游戏者的选择,并且与计算机的选择进行比较。计算机的选择是从选择列表中随机选取的。如果游戏者获胜,则增加1分。

import random

choices = [“Rock”, “Paper”, “Scissors”]

computer = random.choice(choices)

player = False

cpu_score = 0

player_score = 0

while True:

player = input(“Rock, Paper or Scissors?”).capitalize()

判断游戏者和电脑的选择

if player == computer:

print(“Tie!”)

elif player == “Rock”:

if computer == “Paper”:

print(“You lose!”, computer, “covers”, player)

cpu_score+=1

else:

print(“You win!”, player, “smashes”, computer)

player_score+=1

elif player == “Paper”:

if computer == “Scissors”:

print(“You lose!”, computer, “cut”, player)

cpu_score+=1

else:

print(“You win!”, player, “covers”, computer)

player_score+=1

elif player == “Scissors”:

if computer == “Rock”:

print(“You lose…”, computer, “smashes”, player)

cpu_score+=1

else:

print(“You win!”, player, “cut”, computer)

player_score+=1

elif player==‘E’:

print(“Final Scores:”)

print(f"CPU:{cpu_score}")

print(f"Plaer:{player_score}")

break

else:

print(“That’s not a valid play. Check your spelling!”)

computer = random.choice(choices)

8、维基百科文章摘要

使用一种简单的方法从用户提供的文章链接中生成摘要。

你可以使用爬虫获取文章数据,通过提取生成摘要。

from bs4 import BeautifulSoup

import re

import requests

import heapq

from nltk.tokenize import sent_tokenize,word_tokenize

from nltk.corpus import stopwords

url = str(input(“Paste the url”\n"))num = int(input(“Enter the Number of Sentence you want in the summary”))

num = int(num)

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’}#url = str(input(“Paste the url…”))

res = requests.get(url,headers=headers)summary = “”

soup = BeautifulSoup(res.text,‘html.parser’) content = soup.findAll(“p”)

for text in content:

summary +=text.text

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

现在能在网上找到很多很多的学习资源,有免费的也有收费的,当我拿到1套比较全的学习资源之前,我并没着急去看第1节,我而是去审视这套资源是否值得学习,有时候也会去问一些学长的意见,如果可以之后,我会对这套学习资源做1个学习计划,我的学习计划主要包括规划图和学习进度表。

分享给大家这份我薅到的免费视频资料,质量还不错,大家可以跟着学习

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

需要这份系统化学习资料的朋友,可以戳这里获取

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值