I keep getting Runtime Error Issue. Could someone help me resolve this? - PYTHON 3 based
from sys import stdin, stdout, float_info
import re
from math import sin, cos, acos, fabs
CONST_PI = acos(-1.0)
CONST_EPSILON = 2.2204460492503130808472633361816
# CONST_PI = 3.141592653589793
data = []
def solve(a, b, c, d):
a = a + (c / 3600) + (b / 60)
# Checking the latitude and longitude position to determine positive pr negative degree
if d == 'SL' or d == 'WL':
a = -a
a = a * CONST_PI / 180
return a
def distComp(a):
if fabs(a) < CONST_EPSILON:
return 0
elif a > 0:
return 1
else:
return -1
# Input
data = stdin.read().split()
# # Test Input
# data = ['Message', '#513.', 'Received', 'at', '22:30:11.', 'Current', "ship's", 'coordinates', 'are', '41^46\'00"', 'NL',
# 'and', '50^14\'00"', 'WL.', 'An', 'iceberg', 'was', 'noticed', 'at', '41^14\'11"', 'NL', 'and', '51^09\'00"', 'WL.', '===']
# data = ['Message', '#513.', 'Received', 'at', '22:30:11.', 'Current', "ship's", 'coordinates', 'are', '36^46\'00"', 'EL',
# 'and', '50^14\'00"', 'WL.', 'An', 'iceberg', 'was', 'noticed', 'at', '41^14\'11"', 'NL', 'and', '76^09\'00"', 'WL.', '===']
# Message Received
# messageReceived = [int(s) for s in re.findall(r'\b\d+\b', data[4])]
# hh = messageReceived[0]
# mm = messageReceived[1]
# ss = messageReceived[2]
# print('\nMessage Received at: ', hh, mm, ss)
# Ship's Latitude
shipLatitude = [float(s) for s in re.findall(r'\b\d+\b', data[9])]
x1 = shipLatitude[0]
x2 = shipLatitude[1]
x3 = shipLatitude[2]
x4 = data[10]
# print('\nShip Latitude: ', x1, x2, x3, x4)
# Ship's Longitude
shipLongitude = [float(s) for s in re.findall(r'\b\d+\b', data[12])]
y1 = shipLongitude[0]
y2 = shipLongitude[1]
y3 = shipLongitude[2]
y4 = data[13][:2]
# print('\nShip Longitude: ', y1, y2, y3, y4)
# Ice Berg's Latitude
iceBergLatitude = [float(s) for s in re.findall(r'\b\d+\b', data[19])]
a1 = iceBergLatitude[0]
a2 = iceBergLatitude[1]
a3 = iceBergLatitude[2]
a4 = data[20]
# print('\nIce Berg Latitude: ', a1, a2, a3, a4)
# Ice Berg's Longitude
iceBergLongitude = [float(s) for s in re.findall(r'\b\d+\b', data[22])]
b1 = iceBergLongitude[0]
b2 = iceBergLongitude[1]
b3 = iceBergLongitude[2]
b4 = data[23][:2]
# print('\nIce Berg Longitude: ', b1, b2, b3, b4)
shipLatitudeResult = solve(x1, x2, x3, x4)
shipLongitudeResult = solve(y1, y2, y3, y4)
iceBergLatitudeResult = solve(a1, a2, a3, a4)
iceBergLongitudeResult = solve(b1, b2, b3, b4)
dist = 6875.0/2
dist = acos(sin(shipLatitudeResult) * sin(iceBergLatitudeResult) + cos(shipLatitudeResult)
* cos(iceBergLatitudeResult) * cos(shipLongitudeResult - iceBergLongitudeResult)) * dist
print('\nThe distance to the iceberg:', round(dist, 2), 'miles.')
if dist < 100:
print('DANGER!')
Edited by author 30.03.2021 16:37