Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions Beginner/14_address_book.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import json
import os

CONTACTS_FILE = "contacts.json"

def load_contacts():
if os.path.exists(CONTACTS_FILE):
with open(CONTACTS_FILE, "r") as f:
return json.load(f)
return {}

def save_contacts(contacts):
with open(CONTACTS_FILE, "w") as f:
json.dump(contacts, f, indent=4)

def add_contact(contacts):
name = input("Enter name: ")
phone = input("Enter phone number: ")
email = input("Enter email address: ")
contacts[name] = {"phone": phone, "email": email}
save_contacts(contacts)
print(f"Contact '{name}' added.")

def view_contacts(contacts):
if not contacts:
print("No contacts found.")
return
for name, info in contacts.items():
print(f"Name: {name}, Phone: {info['phone']}, Email: {info['email']}")

def delete_contact(contacts):
name = input("Enter the name of the contact to delete: ")
if name in contacts:
del contacts[name]
save_contacts(contacts)
print(f"Contact '{name}' deleted.")
else:
print("Contact not found.")

def main():
contacts = load_contacts()
while True:
print("\nAddress Book Menu:")
print("1. Add Contact")
print("2. View Contacts")
print("3. Delete Contact")
print("4. Exit")
choice = input("Enter your choice: ")

if choice == "1":
add_contact(contacts)
elif choice == "2":
view_contacts(contacts)
elif choice == "3":
delete_contact(contacts)
elif choice == "4":
break
else:
print("Invalid choice. Please try again.")

if __name__ == "__main__":
main()
30 changes: 30 additions & 0 deletions Beginner/15_pomodoro_timer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import time

def countdown(minutes):
seconds = minutes * 60
while seconds > 0:
mins, secs = divmod(seconds, 60)
timer = f"{mins:02d}:{secs:02d}"
print(timer, end="\r")
time.sleep(1)
seconds -= 1

def main():
print("Pomodoro Timer")
while True:
try:
work_minutes = int(input("Enter work duration in minutes: "))
break_minutes = int(input("Enter break duration in minutes: "))
break
except ValueError:
print("Invalid input. Please enter a number.")

while True:
print("Work session started.")
countdown(work_minutes)
print("Work session finished. Take a break!")
countdown(break_minutes)
print("Break finished. Time to get back to work!")

if __name__ == "__main__":
main()
74 changes: 74 additions & 0 deletions Beginner/16_budget_tracker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import json
import os

BUDGET_FILE = "budget.json"

def load_data():
if os.path.exists(BUDGET_FILE):
with open(BUDGET_FILE, "r") as f:
return json.load(f)
return {"income": [], "expenses": []}

def save_data(data):
with open(BUDGET_FILE, "w") as f:
json.dump(data, f, indent=4)

def add_transaction(data, transaction_type):
try:
amount = float(input("Enter amount: "))
description = input("Enter description: ")
data[transaction_type].append({"amount": amount, "description": description})
save_data(data)
print(f"{transaction_type.capitalize()} added.")
except ValueError:
print("Invalid amount. Please enter a number.")

def view_transactions(data):
print("\n--- Income ---")
if not data["income"]:
print("No income recorded.")
else:
for item in data["income"]:
print(f"${item['amount']:.2f}: {item['description']}")

print("\n--- Expenses ---")
if not data["expenses"]:
print("No expenses recorded.")
else:
for item in data["expenses"]:
print(f"${item['amount']:.2f}: {item['description']}")

def calculate_balance(data):
total_income = sum(item["amount"] for item in data["income"])
total_expenses = sum(item["amount"] for item in data["expenses"])
balance = total_income - total_expenses
print(f"\nTotal Income: ${total_income:.2f}")
print(f"Total Expenses: ${total_expenses:.2f}")
print(f"Balance: ${balance:.2f}")

def main():
data = load_data()
while True:
print("\nBudget Tracker Menu:")
print("1. Add Income")
print("2. Add Expense")
print("3. View Transactions")
print("4. View Balance")
print("5. Exit")
choice = input("Enter your choice: ")

if choice == "1":
add_transaction(data, "income")
elif choice == "2":
add_transaction(data, "expenses")
elif choice == "3":
view_transactions(data)
elif choice == "4":
calculate_balance(data)
elif choice == "5":
break
else:
print("Invalid choice. Please try again.")

if __name__ == "__main__":
main()
57 changes: 57 additions & 0 deletions Intermediate/2_adventure_game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import time

def print_slow(text):
for char in text:
print(char, end='', flush=True)
time.sleep(0.03)
print()

def get_choice(choices):
while True:
for i, choice in enumerate(choices, 1):
print(f"{i}. {choice}")
try:
choice = int(input("Enter your choice: "))
if 1 <= choice <= len(choices):
return choice
else:
print("Invalid choice. Please try again.")
except ValueError:
print("Invalid input. Please enter a number.")

def intro():
print_slow("You wake up in a dark, cold room.")
print_slow("You see a door in front of you.")
print_slow("What do you do?")
choice = get_choice(["Open the door", "Look for a light switch"])
if choice == 1:
open_door()
else:
light_switch()

def open_door():
print_slow("The door is locked.")
print_slow("You need a key.")
intro()

def light_switch():
print_slow("You find a light switch and flick it on.")
print_slow("The room is empty except for a small key on the floor.")
print_slow("What do you do?")
choice = get_choice(["Pick up the key", "Go back to the door"])
if choice == 1:
pick_up_key()
else:
open_door()

def pick_up_key():
print_slow("You pick up the key.")
print_slow("You go back to the door and unlock it.")
print_slow("You have escaped the room!")
print_slow("Congratulations!")

def main():
intro()

if __name__ == "__main__":
main()
84 changes: 84 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,69 @@ These projects are ideal for those new to Python. Each project includes a descri

</details>

### 14. Address Book
- **Description**: A simple command-line contact manager.
- **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/14_address_book.py
- **Steps**:
1. Create functions to add, view, and delete contacts.
2. Store contacts in a file (e.g., JSON).
3. Create a main loop to interact with the user.
- **Tips:**

</summary>
<details><summary>Tip 1:</summary>

Use a dictionary to store contact information.

</details>
<details><summary>Tip 2:</summary>

Use the `json` module to save and load contacts from a file.

</details>

### 15. Pomodoro Timer
- **Description**: A time management tool to help you stay focused.
- **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/15_pomodoro_timer.py
- **Steps**:
1. Create a function to run a countdown timer.
2. Prompt the user for work and break durations.
3. Alternate between work and break sessions.
- **Tips:**

</summary>
<details><summary>Tip 1:</summary>

Use the `time` module to pause execution.

</details>
<details><summary>Tip 2:</summary>

Use a loop to alternate between work and break sessions.

</details>

### 16. Budget Tracker
- **Description**: A tool to track your income and expenses.
- **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/16_budget_tracker.py
- **Steps**:
1. Create functions to add income and expenses.
2. Store transactions in a file (e.g., JSON).
3. Calculate and display the current balance.
- **Tips:**

</summary>
<details><summary>Tip 1:</summary>

Use lists of dictionaries to store income and expense transactions.

</details>
<details><summary>Tip 2:</summary>

Use the `json` module to save and load transaction data.

</details>

## Intermediate Projects
These projects are ideal for those with experience in Python. Each project includes a description, steps to follow, and tips for completing it.

Expand Down Expand Up @@ -505,6 +568,27 @@ These projects are ideal for those with experience in Python. Each project inclu
> [!NOTE]
> Working code solutions are in the `/Intermediate` folder.

### 2. Text-based Adventure Game
- **Description**: An interactive fiction game where you can explore and make choices.
- **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Intermediate/2_adventure_game.py
- **Steps**:
1. Create a story with different rooms and choices.
2. Use functions to represent different parts of the story.
3. Get user input to navigate through the story.
- **Tips:**

</summary>
<details><summary>Tip 1:</summary>

Use a dictionary to define the game world, with rooms, descriptions, and choices.

</details>
<details><summary>Tip 2:</summary>

Use a loop to keep the game running until the player reaches an end state.

</details>

## Contributing
Contributions are welcome! If you have project ideas or improvements, feel free to fork the repository and open a pull request.

Expand Down