# http://www.fly.faa.gov/flyfaa/usmap.jsp # http://services.faa.gov/docs/services/airport # 2. Write code to report weather information at various airports. # # I have provided a Python module in this folder named "faa" # that contains a function that you will find helpful. # # Your goal is to write code that will display weather # information for each airport code in the list below. # # Example output for an airport code: # # ORD (Chicago): The temperature is 30.0 F (-1.1 C), and the wind is Northeast at 8.1mph. # # Good luck! airport_codes = ['ORD', 'SFO', 'JFK'] # Your code goes here: from faa import get_weather # Or could have done... # import faa # for code in airport_codes: # data = faa.get_weather(code) for airport in airport_codes: print(get_weather(airport)['name'] + ": The temperature is ", get_weather(airport)['weather']['temp'], "and the wind is", get_weather(airport)['weather']['wind'])
# Classifying things # Classes vs. instances, data attributes, and methods. import faa; class Airport: pass def city() data = faa.get_weather(....) return data['city'] my_airport = Airport() your_airport = Airport() my_airport.code = 'ORD' print("O'Hare Airport serves the city of", my_airport.city()) # print("The temperature is:", my_airport.temp()) # print("The wind is:", my_airport.wind())
import faa data = faa.get_weather('ORD') assert data['city'] == 'Chicago' assert data['name'] == 'Chicago OHare International' assert data['ICAO'] == 'KORD'
def city(): data = faa.get_weather("ORD") return data["city"]
import faa data = faa.get_weather('JFK') assert data['city'] == 'Chicago', "Should be Chicago" assert data['name'] == 'Chicago OHare International' assert data['ICAO'] == 'KORD'
# 2. Write code to report weather information at various airports. # # I have provided a Python module in this folder named "faa" # that contains a function that you will find helpful. # # Your goal is to write code that will display weather # information for each airport code in the list below. # # Example output for an airport code: # # ORD (Chicago): The temperature is 30.0 F (-1.1 C), and the wind is Northeast at 8.1mph. # # Good luck! airport_codes = ['ORD', 'SFO', 'JFK'] # Your code goes here: import faa airport_codes = ['ORD', 'SFO', 'JFK'] # Your code goes here: for airport in airport_codes: result = faa.get_weather(airport) temperature = result['weather']['temp'] wind = result['weather']['wind'] city = result['city'] print(airport,'(',city,') : The temperature is',temperature,', and the wind is',wind) print(result['city'])
def get_city_for(airport): return faa.get_weather(airport)['city']
# 1. Look at these websites first: # # http://www.fly.faa.gov/flyfaa/usmap.jsp # http://services.faa.gov/docs/services/airport # 2. Write code to report weather information at various airports. # # I have provided a Python module in this folder named "faa" # that contains a function that you will find helpful. # # Your goal is to write code that will display weather # information for each airport code in the list below. # # Example output for an airport code: # # ORD (Chicago): The temperature is 30.0 F (-1.1 C), and the wind is Northeast at 8.1mph. # # Good luck! airport_codes = ['ORD', 'SFO', 'JFK'] import faa # Your code goes here: for code in airport_codes: data = faa.get_weather(code) city = data['city'] temp = data['weather']['temp'] wind = data['weather']['wind'] print(code, "(" + data['city'] +")", ": The temperature is", data['weather']['temp'], " and the wind is", data['weather']['wind'])
def get_wind_at(code): data = faa.get_weather(code) return data['weather']['wind']
def temp(self): data = faa.get_weather(self.code) return data['weather']['temp']
def wind(self): data = faa.get_weather(self.code) return data['weather']['wind']
def city(self): data = faa.get_weather(self.code) return data['city']
def city(self): # whenever you call a function (on line 23), it always passes the object on the left of the dot # every method must accept at least one parameter data = faa.get_weather(self.code) return data['city']
def get_temperature_at(airport): return faa.get_weather(airport)['weather']['temp']
def city(airport_obj): data = faa.get_weather(airport_obj.code) return data ['city']
def get_city_for(code): data = faa.get_weather(code) return data['city']
def name(airport_obj): data = faa.get_weather(airport_obj.code) return data ['name']
def get_temperature_at(code): data = faa.get_weather(code) return data['weather']['temp']
import faa data = faa.get_weather("ORD") assert data["city"] == "Chicago", "Should be Chicago" # customize error message assert data["name"] == "Chicago OHare International" assert data["ICAO"] == "KORD"
def get_wind_at(airport): return faa.get_weather(airport)['weather']['wind']