在使用Python的过程中,我最喜欢的就是Python的各种第三方库,能够完成很多操作。 下面就给大家介绍22个通过Python构建的项目,以此来学习Python编程。 大家也可根据项目的目的及提示,自己构建解决方法,提高编程水平。

① 骰子模拟器

目的:创建一个程序来模拟掷骰子。

提示:当用户询问时,使用random模块生成一个1到6之间的数字。

推荐一个Python学习裙,各位小伙伴在学习Python的过程中遇到了什么问题,都可以进群一起交流。610 380 249

② 石头剪刀布游戏

目标:创建一个命令行游戏,游戏者可以在石头、剪刀和布之间进行选择,与计算机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)

③ 随机密码生成器

目标:创建一个程序,可指定密码长度,生成一串随机密码。 提示:创建一个数字+大写字母+小写字母+特殊字符的字符串。根据设定的密码长度随机生成一串密码。

④ 句子生成器

目的:通过用户提供的输入,来生成随机且唯一的句子。 提示:以用户输入的名词、代词、形容词等作为输入,然后将所有数据添加到句子中,并将其组合返回。

⑤ 猜数字游戏

目的:在这个游戏中,任务是创建一个脚本,能够在一个范围内生成一个随机数。如果用户在三次机会中猜对了数字,那么用户赢得游戏,否则用户输。 提示:生成一个随机数,然后使用循环给用户三次猜测机会,根据用户的猜测打印最终的结果。

⑥ 故事生成器

目的:每次用户运行程序时,都会生成一个随机的故事。 提示:random模块可以用来选择故事的随机部分,内容来自每个列表里。

⑦ 邮件地址切片器

目的:编写一个Python脚本,可以从邮件地址中获取用户名和域名。 提示:使用@作为分隔符,将地址分为分为两个字符串。

⑧ 自动发送邮件

目的:编写一个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

⑨ 缩写词 目的:编写一个Python脚本,从给定的句子生成一个缩写词。 提示:你可以通过拆分和索引来获取第一个单词,然后将其组合。

⑩ 文字冒险游戏

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

⑪ 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")

⑫ 闹钟

目的:编写一个创建闹钟的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

⑬ 有声读物

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

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

安装:pyttsx3,PyPDF2

⑭ 天气应用

目的:编写一个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)

⑮ 人脸检测

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

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

安装:OpenCV。

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()

⑯ 提醒应用

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

提示: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)

⑰ 维基百科文章摘要 目的:使用一种简单的方法从用户提供的文章链接中生成摘要。 提示:你可以使用爬虫获取文章数据,通过提取生成摘要。

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)

⑱ 货币换算器

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

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

安装:forex-python

python实现一个简单的项目建议书范文_建议收藏,18个Python迷你项目(附源码)相关推荐

  1. python实现一个简单的项目建议书范文_建议收藏,22个Python迷你项目(附源码)

    Python部落在使用Python的过程中,我最喜欢的就是Python的各种第三方库,能够完成很多操作. 下面就给大家介绍22个通过Python构建的项目,以此来学习Python编程. 大家也可根据项 ...

  2. python量化策略源码_【Python量化投资】趋向系统指标策略 ADX、DMI指标用于股票池(附源码)...

    原标题:[Python量化投资]趋向系统指标策略 ADX.DMI指标用于股票池(附源码) [什么是ADX] ADX(average directional indicator) 平均趋向指数,常用的趋 ...

  3. Java毕设项目蛋糕店会员系统的设计与实现计算机(附源码+系统+数据库+LW)

    Java毕设项目蛋糕店会员系统的设计与实现计算机(附源码+系统+数据库+LW) 项目运行 环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行 ...

  4. python模拟火车订票系统代码_Python3.6实现12306火车票自动抢票,附源码

    原标题:Python3.6实现12306火车票自动抢票,附源码 Python(发音:英[?pa?θ?n],美[?pa?θɑ:n]),是一种面向对象.直译式电脑编程语言,也是一种功能强大的通用型语言,已 ...

  5. 基于netty实现一个简单的支持http和webSocket协议的的服务器(含xxl-job通信模块源码分析)

    文章目录 背景 依赖 包结构 实现 WebSocketServer 业务handler WebSocketServerHandler 测试 xxl-job 源码中基于netty实现的http 总结 参 ...

  6. java写一个简单的浪漫代码_2020浪漫七夕:7款程序员必备表白源码(超炫酷)

    2020七夕将要来临,php中文网给大家准备了七款程序员表白专用源码,让你可以一举俘获美人心,下面就来看一看这七款表白代码大全,包含html.html5.CSS.JQ编写的一些非常简单实用的表白代码, ...

  7. java写一个简单的浪漫代码,2018浪漫七夕:7款程序员必备表白源码(超炫酷)

    2018七夕将要来临,php中文网给大家准备了七款程序员表白专用源码,让你可以一举俘获美人心,下面就来看一看这七款表白代码大全,包含html.html5.CSS.JQ编写的一些非常简单实用的表白代码, ...

  8. 【Python游戏】咱就说Python实现一个蔡徐坤大战篮球的小游戏,可还行? | 附带源码

    相关文件 想学Python的小伙伴可以关注小编的公众号[Python日志] 有很多的资源可以白嫖的哈,不定时会更新一下Python的小知识的哈!! 需要源码的小伙伴可以在公众号回复蔡徐坤大战篮球 Py ...

  9. 1.NetDh框架之数据库操作层--Dapper简单封装,可支持多库实例、多种数据库类型等(附源码和示例代码)...

    1.NetDh框架开始的需求场景 需求场景: 1.之前公司有不同.net项目组,有的项目是用SqlServer做数据库,有的项目是用Oracle,后面也有可能会用到Mysql等,而且要考虑后续扩展成主 ...

最新文章

  1. Canvas做股票数据走势图实践分享(一)
  2. js兼容注意事项--仅供参考
  3. [剑指offer]面试题28:字符串的排列
  4. 如何隐藏所有的导航栏
  5. “进度条”博客——第十三周
  6. 快速在指定文件夹打开命令行
  7. Mac上好用且免费的远程桌面SSH工具(FinalShell)
  8. 解决matlab2019b中文乱码问题
  9. Unicode字符集和多字节字符集
  10. 爬取手机app实例:fiddler抓包爬取汽车之家
  11. 基于kettle的数据集成平台(汇总)
  12. 关于人工智能研究思路的一点设想
  13. 计算机里的文件夹可以加密吗,如何加密电脑中的文件夹
  14. 【独行秀才】macOS Monterey 12.1Beta4(21C5045a)原版镜像
  15. ubuntu看不了bilibili视频
  16. 利用C#2005为你的软件制作小精灵
  17. 关闭危险端口445的简单方法
  18. 最老程序员创业札记:全文检索、数据挖掘、推荐引擎应用26
  19. 程序员实习过程中应该掌握的问问题技巧
  20. Pytorch中tensor维度和torch.max()函数中dim参数的理解

热门文章

  1. 简单易懂的例子解释隐马尔可夫模型
  2. 【免root】停用安卓手机自带的APP
  3. 修复vscode 终端字体间隔过大的问题
  4. 电脑基础知识-电脑不认新硬盘时该怎么办?
  5. log4cpp编译使用
  6. 固定资产管理系统的一般操作流程
  7. 解决问题过程记录: QuickTime初始化失败
  8. MTK 驱动----不开机问题快速分析
  9. MFC编程点滴系列4-有多少MFC可以重来
  10. uni-app:实现H5的录音功能,并上传到服务器