16,016,669 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Thandeka Zulu (Top 12 by date)
Thandeka Zulu
8-Oct-22 5:15am
View
@Richard Thank you so much.
Thandeka Zulu
8-Oct-22 5:14am
View
@OriginalGriff Noted.Thank you
Thandeka Zulu
2-Aug-22 4:15am
View
Thank you
Thandeka Zulu
2-Aug-22 2:47am
View
# This program simulates an email message
class Email:
# This constructor initialises senders email address,and has four variables
def __init__(self,from_address, email_contents):
self.from_address = from_address
self.email_contents = email_contents
self.has_been_read = False
self.is_spam = False
# This function changes "has_been_read" variable from false to true
def mark_as_read(self):
self.has_been_read = True
# This function allows us to print the email, especially when the user want to read
def __str__(self):
return f"From: {self.from_address} \nContent: {self.email_contents} "
# This function changes "is_spam" variable from false to true
def mark_as_spam(self):
self.is_spam = True
# List is created to store emaildetails
inbox = []
# Number of messages in the store are returned via this function
def get_count(inbox):
return len(inbox)
# Email content is returned by this function
def get_email(index):
message = inbox[index]
message.mark_as_read()
print(message)
# Non read emails from the list are returned via this function
def get_unread_emails():
messages =[]
for n, i in enumerate(inbox):
if not i.has_been_read:
message = inbox[n]
messages.append(message)
print(message.email_contents)
return messages
# This function returns a list of all the emails that have been marked as a spam
def get_spam_emails():
print()
messages =[]
for n, i in enumerate(inbox):
if not i.is_spam:
message = inbox[n]
messages.append(message)
print(f"spam: {message.email_contents}")
return messages
def add_spam(index):
messages = inbox[index]
messages.mark_as_spam()
print("Email added to spam")
# Delete function deletes an email in the inbox
def delete(index):
try:
inbox.remove(inbox[index])
print("Email deleted successfully")
except:
print("Error: couldn't delete email")
# This variable store user input, the choice they choose from the menu
user_choice = ""
inbox = []
def add_email(message, email):
send = Email(message, email)
inbox.append(send)
# Initial email
init_emails = [
'Hie how are you,alfred@gmail.com',
'Hie lets meet us,thuba@gmail.com'
]
for i in init_emails:
message, email = i.split(',')
add_email(message,email)
#This is the menu the user will be prompted with to enter choice
while user_choice != "quit":
user_choice = input("What would you like to do - read/mark spam/send/delete/quit?\n").lower()
if user_choice == "read":
print("List of unread email\n")
for i,mail in enumerate(init_emails):
print(f'{i+1}. {mail}')
num = int(input("\nEnter number of email you want to read: "))
get_email(num-1)
#num = int(input("Enter number of email you want to read: "))
#get_email(num-1)
elif user_choice == "mark spam":
print("List of emails\n")
for i,mail in enumerate(init_emails):
print(f'{i}. {mail}')
num = int(input("\nEnter number of email you want to spam :"))
add_spam(num-1)
get_spam_emails()
#add_spam(num-1)
#get_spam_emails()
elif user_choice == "send":
from_address = input("Enter your email address: ")
email_contents = input("Enter email content: ")
add_email(email_contents, from_address)
print("Email sent successfully!")
elif user_choice == "delete":
print("List of emails\n")
for i,mail in enumerate(init_emails):
print(f'{i}. {mail}')
num = int(input("enter number of email to delete"))
delete(num-1)
#num = int(input("enter number of email to delete"))
#delete(num-1)
elif user_choice == "quit":
print("Goodbye")
break
# else alet user that the entry is invalid
else:
print("Oops - incorrect input")
Thandeka Zulu
28-Jul-22 9:00am
View
Will definately look into that. Thank you.
Thandeka Zulu
28-Jul-22 8:58am
View
Thanks for that documentation. Will make the changes, then get back to you
Thandeka Zulu
26-Jul-22 13:32pm
View
Thank you.
Thandeka Zulu
26-Jul-22 10:45am
View
def sum_recursion(index_num, list_numbers):
# When length os a list numbers is equal to 0, the program returns a 0
if len(list_numbers) == 0:
return 0
# When length os index number is greater or equal to length of list numbers, the program returns a 0
elif index_num >= len(list_numbers):
return 0
else:
# Adds sum of all the numbers in the list,up until and including the given index point by making use of recursion
next_index = (index_num + 1, len(list_numbers))[index_num + 1 == 0]
return list_numbers[index_num] + sum_recursion(next_index-1, list_numbers)
# List and index number declaration
list_numbers = [1,4,5,3,12,16]
index_num = 4
# Prints sum of the list depending on the index
print(sum_recursion(index_num-1, list_numbers))
-----------------------------------------------
when I add -1.The program gives no result.
Thandeka Zulu
25-Jul-22 15:41pm
View
@Richard MacCutchan. Thank you so much. May God bless you. I works perfectly
Thandeka Zulu
25-Jul-22 15:41pm
View
@Richard MacCutchan. Thank you so much. May God bless you. I works perfectly
Thandeka Zulu
25-Jul-22 11:30am
View
Thanks for your response
Thandeka Zulu
24-Jul-22 15:31pm
View
I do know that part. I need some assistance on how will I utilise the index inside the function.
Show More