1.py 927 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. x = 0
  2. spisok = []
  3. spisokNomber = []
  4. spisokTime = []
  5. spisokSlov = []
  6. itog = []
  7. with open("test.txt", "r") as file1:
  8. for line in file1:
  9. spisok.append(line)
  10. nomber = int(spisok.index(line)) + 1
  11. spisokNomber.append(nomber)
  12. if nomber % 2 == 0:
  13. print('Четное число')
  14. spisokSlov.append(line)
  15. else:
  16. print('Нечентное число')
  17. spisokTime.append(line.split())
  18. try:
  19. while True:
  20. num = spisokNomber[x]
  21. itog.append(num)
  22. strokaTime = "00:" + str(spisokTime[x])[2:-2] + ",001" + " --> " + "00:" + str(spisokTime[x + 1])[2:-2] + ",001"
  23. itog.append(strokaTime)
  24. slova = str(spisokSlov[x])
  25. itog.append(slova)
  26. x = x + 1
  27. except:
  28. itog = itog[:-1]
  29. print("Конец!")
  30. print(itog)
  31. f = open("777.srt", 'w')
  32. for item in itog:
  33. f.write("%s\n" % item)