Init
This commit is contained in:
commit
c5ca3cf428
36
alt.py
Normal file
36
alt.py
Normal file
@ -0,0 +1,36 @@
|
||||
import sys
|
||||
import csv
|
||||
|
||||
if len(sys.argv) < 4:
|
||||
print('Syntax: ./alt.py $COUNTRY $CITY $VARIANCE')
|
||||
sys.exit(0)
|
||||
|
||||
country = sys.argv[1]
|
||||
city = sys.argv[2]
|
||||
var = float(sys.argv[3])
|
||||
|
||||
data_file = open('data.csv')
|
||||
data = csv.reader(data_file, delimiter=';', quotechar='"')
|
||||
|
||||
my_location = []
|
||||
|
||||
for item in data:
|
||||
if item[1] == country:
|
||||
if item[2] == city:
|
||||
my_location = item
|
||||
break
|
||||
|
||||
if my_location:
|
||||
print('%s, %s has an altitude of %s' % (my_location[2], my_location[1], my_location[5]))
|
||||
else:
|
||||
print('Location not found in data!')
|
||||
sys.exit(0)
|
||||
|
||||
my_altitude = float(my_location[5])
|
||||
print("\n" + 'Here are the cities that share the same altitude with you:' + "\n")
|
||||
|
||||
for item in data:
|
||||
if my_altitude - var < float(item[5]) and my_altitude + var > float(item[5]):
|
||||
print('%s, %s has an altitude of %s' % (item[2], item[1], item[5]))
|
||||
|
||||
data_file.close()
|
Loading…
Reference in New Issue
Block a user