-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from JuanitaCathy/master
Python Script for Expense Tracker
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Expense tracker | ||
|
||
### Usage | ||
|
||
Install the required dependencies using pip: | ||
|
||
``` | ||
pip install -r requirements.txt | ||
``` | ||
|
||
Run the expense.py file to start the bot: | ||
|
||
``` | ||
python expense.py | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import csv | ||
import os | ||
|
||
CSV_FILE = "expenses.csv" | ||
|
||
def initialize_csv(): | ||
if not os.path.exists(CSV_FILE): | ||
with open(CSV_FILE, "w", newline="") as file: | ||
writer = csv.writer(file) | ||
writer.writerow(["Date", "Description", "Amount"]) | ||
|
||
def add_expense(date, description, amount): | ||
with open(CSV_FILE, "a", newline="") as file: | ||
writer = csv.writer(file) | ||
writer.writerow([date, description, amount]) | ||
|
||
def view_expenses(): | ||
with open(CSV_FILE, "r") as file: | ||
reader = csv.reader(file) | ||
for row in reader: | ||
print(", ".join(row)) | ||
|
||
if __name__ == "__main__": | ||
initialize_csv() | ||
|
||
while True: | ||
print("\nExpense Tracker Menu:") | ||
print("1. Add Expense") | ||
print("2. View Expenses") | ||
print("3. Exit") | ||
|
||
choice = input("Enter your choice: ") | ||
|
||
if choice == "1": | ||
date = input("Enter the date (YYYY-MM-DD): ") | ||
description = input("Enter the description: ") | ||
amount = input("Enter the amount: ") | ||
|
||
add_expense(date, description, amount) | ||
print("Expense added successfully!") | ||
|
||
elif choice == "2": | ||
print("Expenses:") | ||
view_expenses() | ||
|
||
elif choice == "3": | ||
break | ||
|
||
else: | ||
print("Invalid choice. Please try again.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
csv | ||
os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters