Skip to content

Commit 6ef85ff

Browse files
authored
Add files via upload
1 parent fa25c87 commit 6ef85ff

File tree

6 files changed

+686
-0
lines changed

6 files changed

+686
-0
lines changed

Projects/Bank Application.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# **Bank Application**
2+
3+
The "Bank Application" is a Python program that simulates basic banking operations. It allows users to create accounts, log in, check balances, deposit and withdraw money, and transfer funds to other accounts. This project is designed to help you practice your Python programming skills, database management, and basic security measures.
4+
5+
### Key Features:
6+
7+
1. **Create Account:** Users can create a new bank account by providing a unique username and password. Passwords are securely hashed using the SHA-256 algorithm before storage.
8+
2. **Login:** Account holders can log in with their usernames and passwords to access their accounts.
9+
3. **Check Balance:** Users can check their account balances.
10+
4. **Deposit:** Account holders can deposit money into their accounts.
11+
5. **Withdraw:** Users can withdraw money from their accounts, provided they have sufficient funds.
12+
6. **Transfer:** Account holders can transfer money to other accounts, ensuring secure fund transfer.
13+
14+
### Project Structure:
15+
16+
- The program uses an SQLite database to store account information, including usernames, hashed passwords, and account balances.
17+
- User passwords are securely hashed using the SHA-256 algorithm before storage to enhance security.
18+
- It includes a `BankApp` class that encapsulates the functionality of the application, making it organized and easy to maintain.
19+
20+
### How to Use:
21+
22+
1. Run the Python program.
23+
2. Select from the available options to create an account, log in, and perform banking operations.
24+
25+
### Why This Project?
26+
27+
This project serves as a practical exercise for intermediate Python programmers. It covers fundamental concepts such as working with databases, user authentication, and class-based application structure. By completing this project, you will improve your Python skills and gain experience in building secure applications.
28+
29+
### Suggested Enhancements:
30+
31+
To further expand and enhance this project, you can consider adding features like:
32+
33+
- User account management: Allow users to change passwords and update account information.
34+
- Transaction history: Keep a record of all transactions for each account.
35+
- Error handling: Implement robust error handling and validation to enhance security.
36+
37+
Feel free to explore and customize this project to suit your learning goals and interests. Happy coding!
38+
39+
```python
40+
import sqlite3
41+
import hashlib
42+
43+
44+
class BankApp:
45+
def __init__(self, db_name):
46+
self.conn = sqlite3.connect(db_name)
47+
self.cursor = self.conn.cursor()
48+
self.create_table()
49+
50+
def create_table(self):
51+
self.cursor.execute('''
52+
CREATE TABLE IF NOT EXISTS accounts (
53+
id INTEGER PRIMARY KEY,
54+
username TEXT,
55+
password TEXT,
56+
balance REAL
57+
)
58+
''')
59+
self.conn.commit()
60+
61+
def create_account(self, username, password):
62+
hashed_password = hashlib.sha256(password.encode()).hexdigest()
63+
self.cursor.execute("INSERT INTO accounts (username, password, balance) VALUES (?, ?, ?)",
64+
(username, hashed_password, 0.0))
65+
self.conn.commit()
66+
67+
def login(self, username, password):
68+
hashed_password = hashlib.sha256(password.encode()).hexdigest()
69+
self.cursor.execute("SELECT * FROM accounts WHERE username=? AND password=?", (username, hashed_password))
70+
account = self.cursor.fetchone()
71+
return account
72+
73+
def check_balance(self, username):
74+
self.cursor.execute("SELECT balance FROM accounts WHERE username=?", (username,))
75+
balance = self.cursor.fetchone()
76+
return balance[0]
77+
78+
def deposit(self, username, amount):
79+
current_balance = self.check_balance(username)
80+
new_balance = current_balance + amount
81+
self.cursor.execute("UPDATE accounts SET balance=? WHERE username=?", (new_balance, username))
82+
self.conn.commit()
83+
84+
def withdraw(self, username, amount):
85+
current_balance = self.check_balance(username)
86+
if amount > current_balance:
87+
return "Insufficient balance"
88+
new_balance = current_balance - amount
89+
self.cursor.execute("UPDATE accounts SET balance=? WHERE username=?", (new_balance, username))
90+
self.conn.commit()
91+
92+
def transfer(self, sender_username, receiver_username, amount):
93+
sender_balance = self.check_balance(sender_username)
94+
if amount > sender_balance:
95+
return "Insufficient balance"
96+
97+
receiver_balance = self.check_balance(receiver_username)
98+
99+
new_sender_balance = sender_balance - amount
100+
new_receiver_balance = receiver_balance + amount
101+
102+
self.cursor.execute("UPDATE accounts SET balance=? WHERE username=?", (new_sender_balance, sender_username))
103+
self.cursor.execute("UPDATE accounts SET balance=? WHERE username=?", (new_receiver_balance, receiver_username))
104+
self.conn.commit()
105+
106+
def close(self):
107+
self.conn.close()
108+
109+
110+
def main():
111+
bank_app = BankApp("bank.db")
112+
113+
while True:
114+
print("\nBank Application.md")
115+
print("1. Create Account")
116+
print("2. Login")
117+
print("3. Exit")
118+
119+
choice = input("Select an operation: ")
120+
121+
if choice == "1":
122+
username = input("Enter a username: ")
123+
password = input("Enter a password: ")
124+
bank_app.create_account(username, password)
125+
print("Account created successfully.")
126+
127+
elif choice == "2":
128+
username = input("Enter your username: ")
129+
password = input("Enter your password: ")
130+
account = bank_app.login(username, password)
131+
if account:
132+
print("Login successful.")
133+
while True:
134+
print("\nAccount Menu")
135+
print("1. Check Balance")
136+
print("2. Deposit")
137+
print("3. Withdraw")
138+
print("4. Transfer")
139+
print("5. Logout")
140+
141+
account_choice = input("Select an operation: ")
142+
143+
if account_choice == "1":
144+
balance = bank_app.check_balance(username)
145+
print(f"Balance: ${balance:.2f}")
146+
147+
elif account_choice == "2":
148+
amount = float(input("Enter deposit amount: "))
149+
bank_app.deposit(username, amount)
150+
print("Deposit successful.")
151+
152+
elif account_choice == "3":
153+
amount = float(input("Enter withdrawal amount: "))
154+
result = bank_app.withdraw(username, amount)
155+
if result == "Insufficient balance":
156+
print("Insufficient balance.")
157+
else:
158+
print("Withdrawal successful.")
159+
160+
elif account_choice == "4":
161+
receiver_username = input("Enter receiver's username: ")
162+
amount = float(input("Enter transfer amount: "))
163+
result = bank_app.transfer(username, receiver_username, amount)
164+
if result == "Insufficient balance":
165+
print("Insufficient balance.")
166+
else:
167+
print("Transfer successful.")
168+
169+
elif account_choice == "5":
170+
break
171+
else:
172+
print("Login failed. Invalid username or password.")
173+
174+
elif choice == "3":
175+
bank_app.close()
176+
break
177+
178+
179+
if __name__ == "__main__":
180+
main()
181+
```

Projects/Dictionary Application.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# **Dictionary Application**
2+
3+
The "Dictionary Application" is a simple Python program that allows users to manage a dictionary of words, their meanings, and example sentences. This project is designed to help you practice your Python programming skills and gain experience in working with databases. It offers the following features:
4+
5+
### Key Features:
6+
7+
1. **Add Word:** Users can add new words to the dictionary, along with their meanings and example sentences.
8+
2. **List Words:** The application displays a list of all the words in the dictionary, including their meanings and example sentences.
9+
3. **Search Word:** Users can search for a specific word in the dictionary to find its meaning and example sentence.
10+
4. **Delete Word:** The application allows users to delete words from the dictionary.
11+
12+
### Project Structure:
13+
14+
- The program uses an SQLite database to store word data, with a table named "words" to manage entries.
15+
- It includes a `DictionaryApp` class that encapsulates the functionality of the application, making it organized and easy to maintain.
16+
- The user interacts with the application through a simple command-line interface.
17+
18+
### How to Use:
19+
20+
1. Run the Python program.
21+
2. Select from the available options to add words, list words, search for words, delete words, or exit the application.
22+
23+
### Why This Project?
24+
25+
This project serves as a practical exercise for beginner and intermediate Python programmers. It covers fundamental concepts such as working with databases, user input, and class-based application structure. By completing this project, you will improve your Python skills and be better equipped for more complex programming tasks.
26+
27+
28+
### Suggested Enhancements:
29+
30+
To further expand and enhance this project, you can consider adding features like:
31+
32+
- Update/Edit Word: Allow users to modify the meaning or example sentence of an existing word.
33+
- User Authentication: Implement user accounts and authentication for managing personal dictionaries.
34+
- Better User Interface: Develop a graphical user interface (GUI) for a more user-friendly experience.
35+
36+
Feel free to explore and customize this project to suit your learning goals and interests. Happy coding!
37+
38+
39+
40+
```python
41+
import sqlite3
42+
43+
class DictionaryApp:
44+
def __init__(self, db_name):
45+
self.conn = sqlite3.connect(db_name)
46+
self.cursor = self.conn.cursor()
47+
self.create_table()
48+
49+
def create_table(self):
50+
self.cursor.execute('''
51+
CREATE TABLE IF NOT EXISTS words (
52+
id INTEGER PRIMARY KEY,
53+
word TEXT,
54+
meaning TEXT,
55+
sentence TEXT
56+
)
57+
''')
58+
self.conn.commit()
59+
60+
def add_word(self, word, meaning, sentence):
61+
self.cursor.execute("INSERT INTO words (word, meaning, sentence) VALUES (?, ?, ?)", (word, meaning, sentence))
62+
self.conn.commit()
63+
64+
def list_words(self):
65+
self.cursor.execute("SELECT * FROM words")
66+
words = self.cursor.fetchall()
67+
return words
68+
69+
def search_word(self, word):
70+
self.cursor.execute("SELECT * FROM words WHERE word=?", (word,))
71+
word = self.cursor.fetchone()
72+
return word
73+
74+
def delete_word(self, word):
75+
self.cursor.execute("DELETE FROM words WHERE word=?", (word,))
76+
self.conn.commit()
77+
78+
def close(self):
79+
self.conn.close()
80+
81+
def main():
82+
dictionary = DictionaryApp("words.db")
83+
84+
while True:
85+
print("\nDictionary Application")
86+
print("1. Add Word")
87+
print("2. List Words")
88+
print("3. Search Word")
89+
print("4. Delete Word")
90+
print("5. Exit")
91+
92+
choice = input("Select an operation: ")
93+
94+
if choice == "1":
95+
word = input("Word: ")
96+
meaning = input("Meaning: ")
97+
sentence = input("Example Sentence: ")
98+
dictionary.add_word(word, meaning, sentence)
99+
print("Word added.")
100+
101+
elif choice == "2":
102+
words = dictionary.list_words()
103+
if words:
104+
print("\nWord List:")
105+
for word in words:
106+
print(f"Word: {word[1]}, Meaning: {word[2]}, Example Sentence: {word[3]}")
107+
else:
108+
print("No words found.")
109+
110+
elif choice == "3":
111+
word = input("Enter Word to Search: ")
112+
result = dictionary.search_word(word)
113+
if result:
114+
print(f"Word: {result[1]}, Meaning: {result[2]}, Example Sentence: {result[3]}")
115+
else:
116+
print("Word not found.")
117+
118+
elif choice == "4":
119+
word = input("Enter Word to Delete: ")
120+
dictionary.delete_word(word)
121+
print("Word deleted.")
122+
123+
elif choice == "5":
124+
dictionary.close()
125+
break
126+
127+
if __name__ == "__main__":
128+
main()
129+
```
130+
131+
This program creates a class called `DictionaryApp` that allows users to add words, list words, search for words, and delete words. It uses an SQLite database named "words.db" to store word data. Before running the program, make sure to create the "words.db" SQLite database file in the same directory or change the database name accordingly.

0 commit comments

Comments
 (0)