Record#
- Today's exercise is: using the method of reading and storing files to save ideas.
CODE#
import os, time, random
while True:
menu=int(input("Add an idea or see a random idea? \n1. ADD\n2. READ\n3. RANDOM\n"))
time.sleep(1)
os.system("clear")
if menu == 1:
f = open("idea.list","a+")
text = input()
f.write(f"{text}\n")
f.close
elif menu == 2:
f =open("idea.list","r")
text = f.read()
print(text)
f.close
elif menu == 3:
f=open("idea.list","r")
idealist=[]
while True:
contents=f.readline().strip().split()
if not contents:
break
idealist.append(contents)
idea = random.choice(idealist)
print(idea)
Translation: