二手产品经理

二手产品经理

THIS IS RENO

File Operations - 48 Days - Learn Python Online in 100 Days

Record#

Catbox

  1. Today I learned about file operations.
  2. Use the open() function to open files, and use different parameters to achieve different opening modes, such as read-only, binary, etc.
  3. Use the write() function to write information to files.
  4. Use the close() function to close files, and the above operations will only be completed after closing.
  5. Today's exercise is to save the user's input content to a file, which is beautiful and generous.

CODE#


print("🌟HIGH SCORE TABLE🌟")
again = "y"
while again == "y":
  initials = input("Input your initials > ")
  score =int(input("Input your score > "))
  
  f = open("scoretable.txt","a+")
  f.write(f"{initials: <5}{score}\n")
  f.close()
  
  print("ADDED")
  again=input("Add another? y/n? ")
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.