当前位置: 首页 > news >正文

百度四川建设厅网站seo文章代写一篇多少钱

百度四川建设厅网站,seo文章代写一篇多少钱,wordpress 分页文章数,网站隐藏php后缀Python3 【函数】项目实战:5 个新颖的学习案例 本文包含5编程学习案例,具体项目如下: 简易聊天机器人待办事项提醒器密码生成器简易文本分析工具简易文件加密解密工具 项目 1:简易聊天机器人 功能描述: 实现一个简易…

Python3 【函数】项目实战:5 个新颖的学习案例

本文包含5编程学习案例,具体项目如下:

  1. 简易聊天机器人
  2. 待办事项提醒器
  3. 密码生成器
  4. 简易文本分析工具
  5. 简易文件加密解密工具

项目 1:简易聊天机器人

功能描述:
实现一个简易聊天机器人,根据用户输入返回预设的响应。

代码:

def chatbot_response(user_input):responses = {"hello": "Hello! How can I help you?","how are you": "I'm just a bot, but I'm doing great!","bye": "Goodbye! Have a nice day!","default": "I'm not sure how to respond to that."}return responses.get(user_input.lower(), responses["default"])# 测试案例
print(chatbot_response("Hello"))  # 输出: Hello! How can I help you?
print(chatbot_response("How are you"))  # 输出: I'm just a bot, but I'm doing great!
print(chatbot_response("What's your name?"))  # 输出: I'm not sure how to respond to that.

执行结果:

Hello! How can I help you?
I'm just a bot, but I'm doing great!
I'm not sure how to respond to that.

项目 2:简易待办事项提醒器

功能描述:
实现一个简易待办事项提醒器,支持添加任务、设置提醒时间,并在指定时间提醒用户。

代码:

import time
from datetime import datetimedef add_task(tasks, task, reminder_time):tasks.append({"task": task, "reminder_time": reminder_time})def check_reminders(tasks):current_time = datetime.now()for task in tasks:if current_time >= task["reminder_time"]:print(f"Reminder: {task['task']} is due now!")tasks.remove(task)# 测试案例
tasks = []
add_task(tasks, "Buy groceries", datetime(2025, 1, 27, 10, 26))  # 设置提醒时间为 2025-1-27 10:26
add_task(tasks, "Read a book", datetime(2025, 1, 27, 10, 28))    # 设置提醒时间为 2025-1-27 10:28while tasks:check_reminders(tasks)time.sleep(60)  # 每分钟检查一次

执行结果:

Reminder: Buy groceries is due now!  # 当时间到达 2025-1-27 10:26 时输出
Reminder: Read a book is due now!    # 当时间到达 2025-1-27 10:28 时输出

项目 3:密码生成器

功能描述:
实现一个密码生成器,生成包含大小写字母、数字和特殊字符的随机密码。

代码:

import random
import stringdef generate_password(length=12):characters = string.ascii_letters + string.digits + string.punctuationpassword = ''.join(random.choice(characters) for _ in range(length))return password# 测试案例
print("Generated Password:", generate_password())  # 输出: 随机生成的密码,如 "A1b@C3d$E5f^"

执行结果:

Generated Password: A1b@C3d$E5f^

项目 4:简易文本分析工具

功能描述:
实现一个简易文本分析工具,统计文本中的单词数量、字符数量和最常见的单词。

代码:

from collections import Counterdef analyze_text(text):words = text.split()word_count = len(words)char_count = len(text)most_common_word = Counter(words).most_common(1)[0][0]return {"word_count": word_count,"char_count": char_count,"most_common_word": most_common_word}# 测试案例
text = "This is a simple text analysis tool. It counts words and characters."
result = analyze_text(text)
print(result)

执行结果:

{'word_count': 12,'char_count': 68,'most_common_word': 'This'
}

项目 5:简易文件加密解密工具

功能描述:
实现一个简易文件加密解密工具,使用简单的字符替换算法对文件内容进行加密和解密。

代码:

def encrypt(text, key):encrypted_text = ""for char in text:encrypted_text += chr(ord(char) + key)return encrypted_textdef decrypt(encrypted_text, key):decrypted_text = ""for char in encrypted_text:decrypted_text += chr(ord(char) - key)return decrypted_textdef encrypt_file(input_file, output_file, key):with open(input_file, 'r') as file:text = file.read()encrypted_text = encrypt(text, key)with open(output_file, 'w') as file:file.write(encrypted_text)def decrypt_file(input_file, output_file, key):with open(input_file, 'r') as file:encrypted_text = file.read()decrypted_text = decrypt(encrypted_text, key)with open(output_file, 'w') as file:file.write(decrypted_text)# 测试案例
encrypt_file("input.txt", "encrypted.txt", 3)  # 加密文件
decrypt_file("encrypted.txt", "decrypted.txt", 3)  # 解密文件

执行结果:

  • 生成 encrypted.txt,内容为加密后的文本。
  • 生成 decrypted.txt,内容与原始文件 input.txt 相同。

总结

以上 5 个迷你项目涵盖了密码生成、待办事项提醒、聊天机器人、文本分析和文件加密解密等新颖且实用的功能。每个项目都附有测试案例和执行结果,适合用于学习和练习 Python 函数的综合应用。

http://www.hkea.cn/news/987286/

相关文章:

  • 小型网站怎样优化百度首页官网
  • 网站开发与iso9001关系百度上做推广怎么做
  • wordpress怎么设置导航镇江seo
  • 番禺建设网站服务软文写作网站
  • 有哪些专做自然风景图片的网站石首seo排名
  • 移动网站虚拟主机seo 排名 优化
  • 专业网站建设课程网站推广优化方式
  • 适合站长做的网站信息流广告投放工作内容
  • 做健身网站步骤网站建设网络公司
  • 武汉整站seo数据上云网站关键词优化怎么做的
  • 网站尾部网络seo推广
  • 建设一个公司网站需要什么知识网站网络推广优化
  • 政府高度重视网站建设怎么做网络推广
  • 自己做的网站是怎么赚钱免费ip地址网站
  • 郑州市政府网站集约化建设计划企业seo排名外包
  • 什么网站可以免费做护师题企业网站管理系统源码
  • 青岛专业餐饮网站制作国内搜索引擎排行榜
  • 域名有哪些seo站长之家
  • 建设网站有哪些关键词制作软件
  • 视频网站怎么制作网店推广的作用是什么
  • 网站栏目怎么做单独的搜索框云南疫情最新消息
  • 独立商城b2c电商网站开发合肥百度seo代理
  • 做购物网站需不需要交税费郑州网站托管
  • 是不是做网站就能赚钱谷歌seo关键词优化
  • 萝岗门户网站建设今日重大新闻头条财经
  • 个人相册网站模板怎么把网站排名排上去
  • 建设外贸网站案例统计站老站长推荐草莓
  • 1688网站的特点全网营销系统
  • 西安做网站企业网址怎么申请
  • 专业网站建设品牌百度指数里的资讯指数是什么