Answer:
class User:
def __init__(self, username, email):
self.username = username
self.email = email
class Post:
def __init__(self, author, title, content):
self.author = author
self.title = title
self.content = content
self.comments = []
def add_comment(self, comment):
self.comments.append(comment)
class Comment:
def __init__(self, author, content):
class Forum:
def __init__(self):
self.users = []
self.posts = []
def register_user(self, username, email):
user = User(username, email)
self.users.append(user)
print(f"User {username} registered successfully!")
def create_post(self, username, title, content):
author = self.find_user(username)
if author:
post = Post(author, title, content)
self.posts.append(post)
print(f"Post '{title}' created successfully!")
else:
print(f"User '{username}' does not exist.")
def add_comment(self, username, post_title, content):
post = self.find_post(post_title)
if author and post:
comment = Comment(author, content)
post.add_comment(comment)
print("Comment added successfully!")
elif not author:
elif not post:
print(f"Post '{post_title}' does not exist.")
def find_user(self, username):
for user in self.users:
if user.username == username:
return user
return None
def find_post(self, post_title):
for post in self.posts:
if post.title == post_title:
return post
# Example Usage:
forum = Forum()
# Register Users
forum.register_user("Alice", "[email protected]")
forum.register_user("Bob", "[email protected]")
forum.register_user("Charlie", "[email protected]")
# Create Posts
forum.create_post("Alice", "Introduction", "Hello, everyone!")
forum.create_post("Bob", "Question", "Can someone help me with math homework?")
forum.create_post("Charlie", "Discussion", "What are your favorite books?")
# Add Comments
forum.add_comment("Bob", "Introduction", "Welcome, Alice!")
forum.add_comment("Alice", "Question", "Sure, what do you need help with?")
forum.add_comment("Charlie", "Question", "I'm not good at math, but I can recommend some books!")
yeah bro i remember you
I never forget my brothers
well am fine what about you..
हम आँसूओ को शराब कहते है
और अाज हम ज़िन्दगी को अज़ाब
कहते हैं
हम से मिलना तो सोच समझ कर
मिलना
हमे लोग अक्सर ख़राब कहते हैं...
Copyright © 2024 EHUB.TIPS team's - All rights reserved.
Answers & Comments
Answer:
class User:
def __init__(self, username, email):
self.username = username
self.email = email
class Post:
def __init__(self, author, title, content):
self.author = author
self.title = title
self.content = content
self.comments = []
def add_comment(self, comment):
self.comments.append(comment)
class Comment:
def __init__(self, author, content):
self.author = author
self.content = content
class Forum:
def __init__(self):
self.users = []
self.posts = []
def register_user(self, username, email):
user = User(username, email)
self.users.append(user)
print(f"User {username} registered successfully!")
def create_post(self, username, title, content):
author = self.find_user(username)
if author:
post = Post(author, title, content)
self.posts.append(post)
print(f"Post '{title}' created successfully!")
else:
print(f"User '{username}' does not exist.")
def add_comment(self, username, post_title, content):
author = self.find_user(username)
post = self.find_post(post_title)
if author and post:
comment = Comment(author, content)
post.add_comment(comment)
print("Comment added successfully!")
elif not author:
print(f"User '{username}' does not exist.")
elif not post:
print(f"Post '{post_title}' does not exist.")
def find_user(self, username):
for user in self.users:
if user.username == username:
return user
return None
def find_post(self, post_title):
for post in self.posts:
if post.title == post_title:
return post
return None
# Example Usage:
forum = Forum()
# Register Users
forum.register_user("Alice", "[email protected]")
forum.register_user("Bob", "[email protected]")
forum.register_user("Charlie", "[email protected]")
# Create Posts
forum.create_post("Alice", "Introduction", "Hello, everyone!")
forum.create_post("Bob", "Question", "Can someone help me with math homework?")
forum.create_post("Charlie", "Discussion", "What are your favorite books?")
# Add Comments
forum.add_comment("Bob", "Introduction", "Welcome, Alice!")
forum.add_comment("Alice", "Question", "Sure, what do you need help with?")
forum.add_comment("Charlie", "Question", "I'm not good at math, but I can recommend some books!")
Answer:
yeah bro i remember you
I never forget my brothers
well am fine what about you..
हम आँसूओ को शराब कहते है
और अाज हम ज़िन्दगी को अज़ाब
कहते हैं
हम से मिलना तो सोच समझ कर
मिलना
हमे लोग अक्सर ख़राब कहते हैं...