Advertisement
PorisulkiP

Номер 25

Jul 13th, 2022 (edited)
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. import random
  2.  
  3. skierPos = 0 # Изначальная позиция лыжника
  4.  
  5. # позиция флага и кол-во движений
  6. flagPos = random.randint(-100000, 100000)
  7. countMove = random.randint(-100000, 100000)
  8. timesHaveDriven = 0 # Сколько раз проехал мимо флага
  9.  
  10. # расстояния
  11. actions = []
  12. for i in range(countMove):
  13.   actions.append(random.randint(-100000, 100000))
  14.  
  15. # Записывам данные в файл
  16. f = open("in-25.txt", "w")
  17. f.write(str(actions))
  18. f.close()
  19. actions.clear()
  20.  
  21. # Читаем всё из файлика
  22. with open("in-25.txt") as f:
  23.   for line in f:
  24.     actions.append([int(x) for x in line.replace("[", "").replace("]", "").replace(",", "").split()])
  25. f.close()
  26.  
  27. for array in actions:
  28.   for i in array:
  29.     oldPos = skierPos
  30.     skierPos += i
  31.     if oldPos < flagPos and skierPos > flagPos or \
  32.        oldPos > flagPos and skierPos < flagPos or \
  33.        skierPos == flagPos:
  34.       timesHaveDriven += 1
  35.        
  36. print("Позиция флага", flagPos)
  37. print("Кол-во перемещений", countMove)
  38. print("Проехал мимо флага", timesHaveDriven, "раз")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement