The program asks the user for some text and puts it into a text file, adding before this the current date and time. If there is already text in the file, the new one must be added without removing the old one. Entries are separated by a blank line.

What is missing in this code?

from datetime import datetime vremja = str(datetime.today()) tekst = input("Введите запись: ") f = open("dnevnik.txt", "a", encoding="UTF-8") f.write(vremja + "\n") f.write(tekst + "\n") f.write("\n") f.close 

Closed due to the fact that it was off topic by Nicolas Chabanovsky 31 May '16 at 7:04 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Nicolas Chabanovsky
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • In addition to the forgotten brackets on the last line, everything seems to be the norm - andreymal
  • Thanks, lost brackets added, but the file is still empty :( - Julia
  • Alas, I'm not empty and everything works) - andreymal
  • Thank you very much! Checked again, really, everything works! - Julia

1 answer 1

On python 3.5, everything works. Do you expect a file in the same directory?

  • Yes. Thank you, it works! The problem was in the lost brackets in the last line. - Julia