Overview
This prompt aims to guide the creation of a simple account management system in Python, focusing on essential programming concepts. Beginner programmers and educators will benefit from the structured approach and detailed explanations provided in the code implementation.
Prompt Overview
“`python
import uuid
class Account:
“””Class representing a user account.”””
def __init__(self, name, email):
self.account_id = str(uuid.uuid4()) # Generate a unique account ID
self.name = name
self.email = email
self.balance = 0.0 # Default balance
class AccountManager:
“””Class to manage user accounts.”””
def __init__(self):
self.accounts = {} # Dictionary to store accounts by account_id
def create_account(self, name, email):
“””Creates a new account with a unique ID and default balance.”””
account = Account(name, email)
self.accounts[account.account_id] = account
return account.account_id
def update_account(self, account_id, name=None, email=None):
“””Updates the name and/or email of the specified account.”””
if account_id not in self.accounts:
raise ValueError(“Account ID does not exist.”)
account = self.accounts[account_id]
if name:
account.name = name
if email:
account.email = email
def view_account(self, account_id):
“””Returns the account details.”””
if account_id not in self.accounts:
raise ValueError(“Account ID does not exist.”)
account = self.accounts[account_id]
return {
“account_id”: account.account_id,
“name”: account.name,
“email”: account.email,
“balance”: account.balance
}
def delete_account(self, account_id):
“””Deletes the account identified by the given ID.”””
if account_id not in self.accounts:
raise ValueError(“Account ID does not exist.”)
del self.accounts[account_id]
Demonstration of the AccountManager functionality
if __name__ == “__main__”:
# Initialize account manager
account_manager = AccountManager()
# Create accounts
acc_id1 = account_manager.create_account(“Alice Smith”, “alice@example.com”)
acc_id2 = account_manager.create_account(“Bob Jones”, “bob@example.com”)
# Update an account
account_manager.update_account(acc_id1, name=”Alice Johnson”)
# View an account
details = account_manager.view_account(acc_id1)
print(details) # Output account details
# Delete an account
account_manager.delete_account(acc_id2)
# Attempt to view deleted account (should raise an error)
try:
account_manager.view_account(acc_id2)
except ValueError as e:
print(e) # Output error message
“`
Quick Specs
- Media: Text
- Use case: Generation
- Industry: Development Tools & DevOps, General Business Operations, Warehousing & Distribution
- Techniques: Role/Persona Prompting, Self-Critique / Reflection, Structured Output
- Models: Claude 3.5 Sonnet, Gemini 2.0 Flash, GPT-4o, Llama 3.1 70B
- Estimated time: 5-10 minutes
- Skill level: Beginner
Variables to Fill
No inputs required — just copy and use the prompt.
Example Variables Block
No example values needed for this prompt.
The Prompt
Write a complete code implementation for a simple account management system in Python that supports creating, updating, viewing, and deleting user accounts.
The system should include:
– An `Account` class with the following properties:
– `account_id` (unique identifier)
– `name`
– `email`
– `balance`
– Methods encapsulated in an `AccountManager` class (or equivalent) to handle the operations below:
– `create_account(name, email)`:
– Creates a new account with a unique system-generated ID and a default balance.
– `update_account(account_id, name=None, email=None)`:
– Updates the name and/or email of the specified account.
– `view_account(account_id)`:
– Returns the account details.
– `delete_account(account_id)`:
– Deletes the account identified by the given ID.
Ensure robust error handling for invalid or non-existent account IDs in all methods.
Also include:
– Detailed comments explaining key parts of the code.
– A main execution block or script section demonstrating:
– Creating several accounts
– Updating an account
– Viewing account details
– Deleting an account
– Outputs illustrating each operation.
– Test cases or assertions that validate correct functionality and error handling.
Adhere to best practices for clarity and security (e.g., do not expose sensitive data unnecessarily).
# Steps
1. Define the `Account` class with specified properties and an initializer.
2. Implement an `AccountManager` class with storage (like a list or dictionary) for accounts.
3. Implement each method with proper validation and error handling.
4. Write a demonstration script using sample data showing all functions.
5. Include comments throughout for explanation.
# Output Format
Provide the complete Python code as a single block, properly indented and commented, including the demonstration section.
# Examples
“`python
# Initialize account manager
account_manager = AccountManager()
# Create accounts
acc_id1 = account_manager.create_account(“Alice Smith”, “alice@example.com”)
acc_id2 = account_manager.create_account(“Bob Jones”, “bob@example.com”)
# Update an account
account_manager.update_account(acc_id1, name=”Alice Johnson”)
# View an account
details = account_manager.view_account(acc_id1)
print(details)
# Delete an account
account_manager.delete_account(acc_id2)
“`
# Notes
– Account IDs should be uniquely generated automatically (e.g., auto-increment or UUID).
– Use Python standard libraries only.
– Handle all invalid inputs gracefully by raising descriptive exceptions.
– Balance can default to zero or a specified initial amount.
– Ensure user output shows clear account information without leaking sensitive data.
Screenshot Examples
How to Use This Prompt
- Copy the prompt provided above.
- Paste the prompt into your coding environment.
- Run the prompt to generate the Python code.
- Review the generated code for accuracy and completeness.
- Execute the code to test the account management system.
- Modify the code as needed for your specific requirements.
Tips for Best Results
- “`python
- import uuid
- class Account:
- def __init__(self, name, email):
- self
- account_id = str(uuid
- uuid4()) # Generate a unique ID
- self
- name = name
- self
- email = email
- self
- balance = 0
- 0 # Default balance
- class AccountManager:
- def __init__(self):
- self
- accounts = {} # Dictionary to store accounts by account_id
- def create_account(self, name, email):
- """Creates a new account with a unique ID and default balance
- """
- new_account = Account(name, email)
- self
- accounts[new_account
- account_id] = new_account
- return new_account
- account_id
- def update_account(self, account_id, name=None, email=None):
- """Updates the name and/or email of the specified account
- """
- if account_id not in self
- accounts:
- raise ValueError("Account ID does not exist
- ")
- account = self
- accounts[account_id]
- if name:
- account
- name = name
- if email:
- account
- email = email
- def view_account(self, account_id):
- """Returns the account details
- """
- if account_id not in self
- accounts:
- raise ValueError("Account ID does not exist
- ")
- account = self
- accounts[account_id]
- return {
- "account_id": account
- account_id,
- "name": account
- name,
- "email": account
- email,
- "balance": account
- balance
- }
- def delete_account(self, account_id):
- """Deletes the account identified by the given ID
- """
- if account_id not in self
- accounts:
- raise ValueError("Account ID does not exist
- ")
- del self
- accounts[account_id]
- # Demonstration of the account management system
- if __name__ == "__main__":
- # Initialize account manager
- account_manager = AccountManager()
- # Create accounts
- acc_id1 = account_manager
- create_account("Alice Smith", "alice@example
- com")
- acc_id2 = account_manager
- create_account("Bob Jones", "bob@example
- com")
- # Update an account
- account_manager
- update_account(acc_id1, name="Alice Johnson")
- # View an account
- details = account_manager
- view_account(acc_id1)
- print("Account Details:", details)
- # Delete an account
- account_manager
- delete_account(acc_id2)
- # Attempt to view deleted account (should raise an error)
- try:
- account_manager
- view_account(acc_id2)
- except ValueError as e:
- print("Error:", e)
- “`
FAQ
- What is the purpose of the Account class?
The Account class defines properties like account_id, name, email, and balance for user accounts. - How does create_account function work?
It generates a unique ID and initializes a new account with a default balance. - What happens if an invalid account_id is provided?
The methods raise descriptive exceptions to handle invalid or non-existent account IDs. - What does the view_account method return?
It returns the details of the account associated with the provided account_id.
Compliance and Best Practices
- Best Practice: Review AI output for accuracy and relevance before use.
- Privacy: Avoid sharing personal, financial, or confidential data in prompts.
- Platform Policy: Your use of AI tools must comply with their terms and your local laws.
Revision History
- Version 1.0 (February 2026): Initial release.


