Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- skierPos = 0 # Изначальная позиция лыжника
- # позиция флага и кол-во движений
- flagPos = random.randint(-100000, 100000)
- countMove = random.randint(-100000, 100000)
- timesHaveDriven = 0 # Сколько раз проехал мимо флага
- # расстояния
- actions = []
- for i in range(countMove):
- actions.append(random.randint(-100000, 100000))
- # Записывам данные в файл
- f = open("in-25.txt", "w")
- f.write(str(actions))
- f.close()
- actions.clear()
- # Читаем всё из файлика
- with open("in-25.txt") as f:
- for line in f:
- actions.append([int(x) for x in line.replace("[", "").replace("]", "").replace(",", "").split()])
- f.close()
- for array in actions:
- for i in array:
- oldPos = skierPos
- skierPos += i
- if oldPos < flagPos and skierPos > flagPos or \
- oldPos > flagPos and skierPos < flagPos or \
- skierPos == flagPos:
- timesHaveDriven += 1
- print("Позиция флага", flagPos)
- print("Кол-во перемещений", countMove)
- print("Проехал мимо флага", timesHaveDriven, "раз")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement