Records#
- Continue learning arrays today. Defining repetitive and reusable code as functions can improve the aesthetics of the code.
- Create a numbered list for the array.
- Method 1. Define a counter when printing, and increase it by 1 each time in the loop.
- Method 2. Use the index of the for loop with range.
- Today's exercise is to add option 4 to the case. It's relatively simple and not difficult.
import os, time
listOfEmail = []
def prettyPrint():
os.system("clear")
print("listofEmail")
print()
for index in range(len(listOfEmail)): # len counts how many items in a list
print(f"{index}: {listOfEmail[index]}")
time.sleep(1)
def spamming():
os.system("clear")
print("SPAMMING")
print()
for i in range(10):
os.system("clear")
print(f"spamming {i}")
time.sleep(2)
while True:
print("SPAMMER Inc.")
menu = input("1. Add email\n2: Remove email\n3. Show emails\n4. Get SPAMMING\n> ")
if menu == "1":
email = input("Email > ")
listOfEmail.append(email)
elif menu =="2":
email = input ("Email > ")
if email in listOfEmail:
listOfEmail.remove(email)
elif menu == "3":
prettyPrint()
elif menu == "4":
spamming()
time.sleep(1)
os.system("clear")