開發社區您好!我是 Andre,一位熱衷於深入 Python 世界的初學者程式設計師。在與動力鬥爭了幾年之後,我決定將注意力轉移到建立真正的專案上。今天,我想分享關於創建我的第一個 Python 專案的故事:個人支出追蹤器 (PET) 應用程式。 (代碼在最後)
個人開支追蹤器是一款命令列應用程序,旨在幫助用戶記錄日常開支、對其進行分類並深入了解他們的消費習慣。我的目標是創建一個工具,使用戶能夠控制自己的財務。 (還有我的!啊哈)
我面臨的最重大挑戰之一是弄清楚如何有效地儲存費用資料。我最初在 Python 中處理文件時遇到了困難,但經過一番堅持,我終於實現了一個可行的解決方案!
透過這個項目,我了解了使用者輸入驗證和確保資料記錄一致的重要性。我還獲得了使用 Python 管理文件以儲存和檢索費用記錄的寶貴經驗。
展望未來,我計劃整合資料視覺化功能,幫助使用者直觀地看到他們的消費模式。另外,我很高興能夠實現一個預算工具,允許用戶按類別設定支出限額。
完成個人支出追蹤器是一次非常有益的經歷,增強了我作為開發人員的信心。我渴望繼續我的後端開發和 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中文網其他相關文章!