Last active
October 10, 2015 04:09
-
-
Save rkhapov/63aa1f1850c897e42fdd to your computer and use it in GitHub Desktop.
Решение задачи с урока 03.10.15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def sqr(a): | |
return a*a | |
def compute_distance(x1, y1, x2, y2): | |
return math.sqrt(sqr(x2 - x1) + sqr(y2 - y1)) | |
try: | |
fp = open("file.data", "r") | |
except OSError: | |
print("Cann't open file.data") | |
exit(1) | |
file_data = fp.readlines() | |
max_local_veocity = 0.0 | |
summ_distance = 0.0 | |
prev_x, prev_y, last_time = list(map(float, file_data[0].split())) | |
for i in range(1, len(file_data)): | |
x, y, t = list(map(float, file_data[i].split())) | |
summ_distance += compute_distance(prev_x, prev_y, x, y) | |
max_local_veocity = max(max_local_veocity, compute_distance(prev_x, prev_y, x, y) / (t - last_time)) | |
prev_x = x | |
prev_y = y | |
last_time = t | |
print("Max local velocity: " + str(max_local_veocity)) | |
print("Avarage speed: " + str(summ_distance / last_time)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment