
您好,dev 社区!我是 andre,一位热衷于深入 python 世界的初学者程序员。在与动力斗争了几年之后,我决定将注意力转移到构建真正的项目上。今天,我想分享关于创建我的第一个 python 项目的故事:个人支出跟踪器 (pet) 应用程序。 (代码在最后)
个人开支跟踪器是一款命令行应用程序,旨在帮助用户记录日常开支、对其进行分类并深入了解他们的消费习惯。我的目标是创建一种工具,使用户能够控制自己的财务。 (还有我的!啊哈)
我面临的最重大挑战之一是弄清楚如何有效地存储费用数据。我最初在 python 中处理文件时遇到了困难,但经过一番坚持,我终于实现了一个可行的解决方案!
通过这个项目,我了解了用户输入验证和确保数据记录一致的重要性。我还获得了使用 python 管理文件以存储和检索费用记录的宝贵经验。
立即学习“Python免费学习笔记(深入)”;
展望未来,我计划集成数据可视化功能,帮助用户直观地看到他们的消费模式。另外,我很高兴能够实现一个预算工具,允许用户按类别设置支出限额。
本文档主要讲述的是Flash Builder操作指南;Flash Builder将构成应用程序的资源(文件夹和文件)组合到一个容器中,我们将其称为项目。项目包含一组属性,这些属性控制应用程序的构建方式、构建的应用程序所在的位置、调试的处理方式以及该项目于工作空间中其他项目的关系。希望本文档会给有需要的朋友带来帮助;感兴趣的朋友可以过来看看
0
完成个人支出跟踪器是一次非常有益的经历,增强了我作为开发人员的信心。我渴望继续我的后端开发和 devops 学习之旅,更多项目即将到来!
我很想听听您的反馈!如果您构建了类似的东西或有增强费用跟踪器的技巧,请分享您的见解!
`
def pet():
print(“欢迎来到 pet!”)
print(“您的个人开支跟踪器,帮助您跟踪您的开支。”)
print("费用类别:")
print("[1] 食品和杂货")
print("[2] 交通(燃油、公共交通等...)")
print("[3] 公用事业(电力、水、互联网等...)")
print("[4] 娱乐休闲")
print("[5] 医疗保健和医疗费用")
print("[6] 租金和抵押贷款")
print("[7] 杂项(任何未分类的费用)")
categories = [
"Food & Groceries",
"Transportation (Fuel, Public Transportation, etc...)",
"Utilities (Electricity, Water, Internet, etc...)",
"Entertainment & Leisure",
"Healthcare & Medical Expenses",
"Rent & Mortgage",
"Miscellaneous (for any uncategorized expenses)"
]
food = []
transportation = []
utilities = []
entertainment = []
healthcare = []
rent = []
miscs = []
while True:
while True:
try:
choice = int(input("Select category: "))
if 1 <= choice <= 7:
break
else:
raise ValueError
except ValueError:
return "Choose a valid category!"
while True:
try:
amount = float(input("Amount: "))
break
except ValueError:
return "Invalid number! Enter the amount of the expense."
if choice == 1:
food.append(amount)
print(f"${amount} added to {categories[0]}")
elif choice == 2:
transportation.append(amount)
print(f"${amount} added to {categories[1]}")
elif choice == 3:
utilities.append(amount)
print(f"${amount} added to {categories[2]}")
elif choice == 4:
entertainment.append(amount)
print(f"${amount} added to {categories[3]}")
elif choice == 5:
healthcare.append(amount)
print(f"${amount} added to {categories[4]}")
elif choice == 6:
rent.append(amount)
print(f"${amount} added to {categories[5]}")
elif choice == 7:
miscs.append(amount)
print(f"${amount} added to {categories[6]}")
option = input("Do you want to add another expense? (Y/N)").lower()
if option != 'y':
break
else:
continue
food_total = sum(food)
transportation_total = sum(transportation)
utilities_total = sum(utilities)
entertainment_total = sum(entertainment)
healthcare_total = sum(healthcare)
rent_total = sum(rent)
miscs_total = sum(miscs)
print("Options:")
print("[1] View total spent")
print("[2] View total per category")
while True:
try:
show_expenses = int(input("Choose an option: "))
if 1 <= show_expenses <= 2:
break
else:
raise ValueError
except ValueError:
return "Invalid! Insert a valid option."
if show_expenses == 1:
total_expenses = food_total + transportation_total + utilities_total + entertainment_total + healthcare_total + rent_total + miscs_total
print(f"Your total expenses: ${total_expenses}")
elif show_expenses == 2:
print(f"{categories[0]} total is: ${food_total}")
print(f"{categories[1]} total is: ${transportation_total}")
print(f"{categories[2]} total is: ${utilities_total}")
print(f"{categories[3]} total is: ${entertainment_total}")
print(f"{categories[4]} total is: ${healthcare_total}")
print(f"{categories[5]} total is: ${rent_total}")
print(f"{categories[6]} total is: ${miscs_total}")
宠物()
`
以上就是我如何构建我的第一个 Python PET 应用程序(以及我学到的东西)的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号