Advertisement
DacCum

xcvbnm

May 3rd, 2022
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1.  
  2. def calc(file):
  3.   arr = file.readlines()
  4.   arr_2 = []
  5.   for i in arr:
  6.     s = ""
  7.     for j in range(len(i)):
  8.       tmp = i[j]
  9.       if (tmp >= '0' and tmp <= '9') or tmp == '.':
  10.         s = s + tmp
  11.       elif s != "":
  12.         arr_2.append(float(s))
  13.         s = ""
  14.     if s != "":
  15.       arr_2.append(float(s))
  16.   return arr_2
  17.  
  18. inputFile = 0
  19. try:
  20.   inputFile = open('TF14_1.txt', 'w')
  21. except IOError:
  22.   print("File TF14_1.txt could not be opened")
  23. else:
  24.   print("Opening file TF14_1.txt for writing.")
  25.  
  26. inputFile.write('12354.13542' + '\n' + '78954.1235 1243.43' + '\n' + ' linelineline 3' + '452')
  27. inputFile.close()
  28.  
  29. try:
  30.   inputFile = open('TF14_1.txt', 'r')
  31. except IOError:
  32.   print("File TF14_1.txt could not be opened")
  33. else:
  34.   print("Opening file TF14_1.txt for reading.")
  35.  
  36. arr = calc(inputFile)
  37. inputFile.close()
  38.  
  39. outputFile = 0
  40. try:
  41.   outputFile = open('TF14_2.txt', 'w')
  42. except IOError:
  43.   print("File TF14_1.txt could not be opened")
  44. else:
  45.   print("Opening file TF14_2.txt for writing.")
  46.  
  47. for i in arr:
  48.   outputFile.write(f"{i} ")
  49. outputFile.write("\n")
  50. outputFile.close()
  51. try:
  52.   outputFile = open('TF14_2.txt', 'r')
  53. except IOError:
  54.   print("File TF14_1.txt could not be opened")
  55. else:
  56.   print("Opening file TF14_2.txt for reading.")
  57.  
  58. arr_2 = calc(outputFile)
  59. max = arr_2[0]
  60. for i in arr_2:
  61.   if max < i:
  62.     max = i
  63. outputFile.close()
  64. print(arr_2)
  65. print(f"maximum: {max}")
  66.  
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement