Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1daf3d4

Browse files
Merge pull request #2 from Infinitode/feature/python-project-ideas
Feat: Add new Python project ideas and update README
2 parents aad143f + 652c562 commit 1daf3d4

File tree

5 files changed

+307
-0
lines changed

5 files changed

+307
-0
lines changed

‎Beginner/14_address_book.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import json
2+
import os
3+
4+
CONTACTS_FILE = "contacts.json"
5+
6+
def load_contacts():
7+
if os.path.exists(CONTACTS_FILE):
8+
with open(CONTACTS_FILE, "r") as f:
9+
return json.load(f)
10+
return {}
11+
12+
def save_contacts(contacts):
13+
with open(CONTACTS_FILE, "w") as f:
14+
json.dump(contacts, f, indent=4)
15+
16+
def add_contact(contacts):
17+
name = input("Enter name: ")
18+
phone = input("Enter phone number: ")
19+
email = input("Enter email address: ")
20+
contacts[name] = {"phone": phone, "email": email}
21+
save_contacts(contacts)
22+
print(f"Contact '{name}' added.")
23+
24+
def view_contacts(contacts):
25+
if not contacts:
26+
print("No contacts found.")
27+
return
28+
for name, info in contacts.items():
29+
print(f"Name: {name}, Phone: {info['phone']}, Email: {info['email']}")
30+
31+
def delete_contact(contacts):
32+
name = input("Enter the name of the contact to delete: ")
33+
if name in contacts:
34+
del contacts[name]
35+
save_contacts(contacts)
36+
print(f"Contact '{name}' deleted.")
37+
else:
38+
print("Contact not found.")
39+
40+
def main():
41+
contacts = load_contacts()
42+
while True:
43+
print("\nAddress Book Menu:")
44+
print("1. Add Contact")
45+
print("2. View Contacts")
46+
print("3. Delete Contact")
47+
print("4. Exit")
48+
choice = input("Enter your choice: ")
49+
50+
if choice == "1":
51+
add_contact(contacts)
52+
elif choice == "2":
53+
view_contacts(contacts)
54+
elif choice == "3":
55+
delete_contact(contacts)
56+
elif choice == "4":
57+
break
58+
else:
59+
print("Invalid choice. Please try again.")
60+
61+
if __name__ == "__main__":
62+
main()

‎Beginner/15_pomodoro_timer.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import time
2+
3+
def countdown(minutes):
4+
seconds = minutes * 60
5+
while seconds > 0:
6+
mins, secs = divmod(seconds, 60)
7+
timer = f"{mins:02d}:{secs:02d}"
8+
print(timer, end="\r")
9+
time.sleep(1)
10+
seconds -= 1
11+
12+
def main():
13+
print("Pomodoro Timer")
14+
while True:
15+
try:
16+
work_minutes = int(input("Enter work duration in minutes: "))
17+
break_minutes = int(input("Enter break duration in minutes: "))
18+
break
19+
except ValueError:
20+
print("Invalid input. Please enter a number.")
21+
22+
while True:
23+
print("Work session started.")
24+
countdown(work_minutes)
25+
print("Work session finished. Take a break!")
26+
countdown(break_minutes)
27+
print("Break finished. Time to get back to work!")
28+
29+
if __name__ == "__main__":
30+
main()

‎Beginner/16_budget_tracker.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import json
2+
import os
3+
4+
BUDGET_FILE = "budget.json"
5+
6+
def load_data():
7+
if os.path.exists(BUDGET_FILE):
8+
with open(BUDGET_FILE, "r") as f:
9+
return json.load(f)
10+
return {"income": [], "expenses": []}
11+
12+
def save_data(data):
13+
with open(BUDGET_FILE, "w") as f:
14+
json.dump(data, f, indent=4)
15+
16+
def add_transaction(data, transaction_type):
17+
try:
18+
amount = float(input("Enter amount: "))
19+
description = input("Enter description: ")
20+
data[transaction_type].append({"amount": amount, "description": description})
21+
save_data(data)
22+
print(f"{transaction_type.capitalize()} added.")
23+
except ValueError:
24+
print("Invalid amount. Please enter a number.")
25+
26+
def view_transactions(data):
27+
print("\n--- Income ---")
28+
if not data["income"]:
29+
print("No income recorded.")
30+
else:
31+
for item in data["income"]:
32+
print(f"${item['amount']:.2f}: {item['description']}")
33+
34+
print("\n--- Expenses ---")
35+
if not data["expenses"]:
36+
print("No expenses recorded.")
37+
else:
38+
for item in data["expenses"]:
39+
print(f"${item['amount']:.2f}: {item['description']}")
40+
41+
def calculate_balance(data):
42+
total_income = sum(item["amount"] for item in data["income"])
43+
total_expenses = sum(item["amount"] for item in data["expenses"])
44+
balance = total_income - total_expenses
45+
print(f"\nTotal Income: ${total_income:.2f}")
46+
print(f"Total Expenses: ${total_expenses:.2f}")
47+
print(f"Balance: ${balance:.2f}")
48+
49+
def main():
50+
data = load_data()
51+
while True:
52+
print("\nBudget Tracker Menu:")
53+
print("1. Add Income")
54+
print("2. Add Expense")
55+
print("3. View Transactions")
56+
print("4. View Balance")
57+
print("5. Exit")
58+
choice = input("Enter your choice: ")
59+
60+
if choice == "1":
61+
add_transaction(data, "income")
62+
elif choice == "2":
63+
add_transaction(data, "expenses")
64+
elif choice == "3":
65+
view_transactions(data)
66+
elif choice == "4":
67+
calculate_balance(data)
68+
elif choice == "5":
69+
break
70+
else:
71+
print("Invalid choice. Please try again.")
72+
73+
if __name__ == "__main__":
74+
main()

‎Intermediate/2_adventure_game.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import time
2+
3+
def print_slow(text):
4+
for char in text:
5+
print(char, end='', flush=True)
6+
time.sleep(0.03)
7+
print()
8+
9+
def get_choice(choices):
10+
while True:
11+
for i, choice in enumerate(choices, 1):
12+
print(f"{i}. {choice}")
13+
try:
14+
choice = int(input("Enter your choice: "))
15+
if 1 <= choice <= len(choices):
16+
return choice
17+
else:
18+
print("Invalid choice. Please try again.")
19+
except ValueError:
20+
print("Invalid input. Please enter a number.")
21+
22+
def intro():
23+
print_slow("You wake up in a dark, cold room.")
24+
print_slow("You see a door in front of you.")
25+
print_slow("What do you do?")
26+
choice = get_choice(["Open the door", "Look for a light switch"])
27+
if choice == 1:
28+
open_door()
29+
else:
30+
light_switch()
31+
32+
def open_door():
33+
print_slow("The door is locked.")
34+
print_slow("You need a key.")
35+
intro()
36+
37+
def light_switch():
38+
print_slow("You find a light switch and flick it on.")
39+
print_slow("The room is empty except for a small key on the floor.")
40+
print_slow("What do you do?")
41+
choice = get_choice(["Pick up the key", "Go back to the door"])
42+
if choice == 1:
43+
pick_up_key()
44+
else:
45+
open_door()
46+
47+
def pick_up_key():
48+
print_slow("You pick up the key.")
49+
print_slow("You go back to the door and unlock it.")
50+
print_slow("You have escaped the room!")
51+
print_slow("Congratulations!")
52+
53+
def main():
54+
intro()
55+
56+
if __name__ == "__main__":
57+
main()

‎README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,69 @@ These projects are ideal for those new to Python. Each project includes a descri
470470

471471
</details>
472472

473+
### 14. Address Book
474+
- **Description**: A simple command-line contact manager.
475+
- **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/14_address_book.py
476+
- **Steps**:
477+
1. Create functions to add, view, and delete contacts.
478+
2. Store contacts in a file (e.g., JSON).
479+
3. Create a main loop to interact with the user.
480+
- **Tips:**
481+
482+
</summary>
483+
<details><summary>Tip 1:</summary>
484+
485+
Use a dictionary to store contact information.
486+
487+
</details>
488+
<details><summary>Tip 2:</summary>
489+
490+
Use the `json` module to save and load contacts from a file.
491+
492+
</details>
493+
494+
### 15. Pomodoro Timer
495+
- **Description**: A time management tool to help you stay focused.
496+
- **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/15_pomodoro_timer.py
497+
- **Steps**:
498+
1. Create a function to run a countdown timer.
499+
2. Prompt the user for work and break durations.
500+
3. Alternate between work and break sessions.
501+
- **Tips:**
502+
503+
</summary>
504+
<details><summary>Tip 1:</summary>
505+
506+
Use the `time` module to pause execution.
507+
508+
</details>
509+
<details><summary>Tip 2:</summary>
510+
511+
Use a loop to alternate between work and break sessions.
512+
513+
</details>
514+
515+
### 16. Budget Tracker
516+
- **Description**: A tool to track your income and expenses.
517+
- **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/16_budget_tracker.py
518+
- **Steps**:
519+
1. Create functions to add income and expenses.
520+
2. Store transactions in a file (e.g., JSON).
521+
3. Calculate and display the current balance.
522+
- **Tips:**
523+
524+
</summary>
525+
<details><summary>Tip 1:</summary>
526+
527+
Use lists of dictionaries to store income and expense transactions.
528+
529+
</details>
530+
<details><summary>Tip 2:</summary>
531+
532+
Use the `json` module to save and load transaction data.
533+
534+
</details>
535+
473536
## Intermediate Projects
474537
These projects are ideal for those with experience in Python. Each project includes a description, steps to follow, and tips for completing it.
475538

@@ -505,6 +568,27 @@ These projects are ideal for those with experience in Python. Each project inclu
505568
> [!NOTE]
506569
> Working code solutions are in the `/Intermediate` folder.
507570
571+
### 2. Text-based Adventure Game
572+
- **Description**: An interactive fiction game where you can explore and make choices.
573+
- **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Intermediate/2_adventure_game.py
574+
- **Steps**:
575+
1. Create a story with different rooms and choices.
576+
2. Use functions to represent different parts of the story.
577+
3. Get user input to navigate through the story.
578+
- **Tips:**
579+
580+
</summary>
581+
<details><summary>Tip 1:</summary>
582+
583+
Use a dictionary to define the game world, with rooms, descriptions, and choices.
584+
585+
</details>
586+
<details><summary>Tip 2:</summary>
587+
588+
Use a loop to keep the game running until the player reaches an end state.
589+
590+
</details>
591+
508592
## Contributing
509593
Contributions are welcome! If you have project ideas or improvements, feel free to fork the repository and open a pull request.
510594

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /