二手产品经理

二手产品经理

THIS IS RENO

Operating Files - 50 Days - Learn Python Online for 100 Days

Record#

  1. 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:

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.