More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
post
page
Python IDE Dashboard

Weather Forecast API

weather-iconsThe aim of this challenge is to write a computer program to display a 5-day weather forecast for a specific location chosen by the end-user.

You program will:

  • retrieve the city from the end user (input),
  • Use the Open Weather Map API to retrieve an up-to-date weather forecast for this city,
  • parse the retrieved information,
  • display the 5-day weather forecast for the selected location. (output)

In order to do so you will use the Open Weather Map API: https://openweathermap.org/api

You will need to sign in to get an API key.

Then you will be able to make the relevant API calls such as the one described in the tabs below.

JSON or XML?


JSON and XML are two widely used choices for open data interchange.

Initially, XML (eXtensible Markup Language) was the only choice for open data interchange. But over the years the world of open data sharing has evolved a lot. The more lightweight JSON (JavaScript Object Notation) has become a popular alternative to XML for various reasons, one of the main reason being that JSON is more compact, faster and lighter (in terms of memory requirements) to process/parse.

The Open Weather Map API let you choose the format of the data to be retrieved using either the JSON format or XML format. (See examples provided below). So you will have to decide which format to use.

You can read and complete the following two challenges which demonstrate how to use a JSON API using Python code. These challenges will help you find out how to make an API call and how to parse a basic JSON data set.

Open Weather Map API


Here are a few examples of how to use the Open Weather Map API to retrieve JSON or XML data sets.

Current Weather - JSONCurrent Weather - XML5 Day Weather Forecast - JSON5 Day Weather Forecast - XML
API Call

https://api.openweathermap.org/data/2.5/weather?q=London&appid=...

Output

{
"coord":{"lon":-0.13,"lat":51.51},
"weather":[{"id":300,"main":"Drizzle","description":"light intensity drizzle","icon":"09d"}],
"base":"stations",
"main":{"temp":280.32,"pressure":1012,"humidity":81,"temp_min":279.15,"temp_max":281.15},
"visibility":10000,
"wind":{"speed":4.1,"deg":80},
"clouds":{"all":90},
"dt":1485789600,
"sys":{"type":1,"id":5091,"message":0.0103,"country":"GB","sunrise":1485762037,"sunset":1485794875},
"id":2643743,
"name":"London",
"cod":200
}

Find out more about date and time format using a UNIX Timestamp.

API Call

https://api.openweathermap.org/data/2.5/weather?q=London&mode=xml&appid=...

Output

<current>
<city id="2643743" name="London">
<coord lon="-0.13" lat="51.51"/>
<country>GB</country>
<sun rise="2017-01-30T07:40:36" set="2017-01-30T16:47:56"/>
</city>
<temperature value="280.15" min="278.15" max="281.15" unit="kelvin"/>
<humidity value="81" unit="%"/>
<pressure value="1012" unit="hPa"/>
<wind>
<speed value="4.6" name="Gentle Breeze"/>
<gusts/>
<direction value="90" code="E" name="East"/>
</wind>
<clouds value="90" name="overcast clouds"/>
<visibility value="10000"/>
<precipitation mode="no"/>
<weather number="701" value="mist" icon="50d"/>
<lastupdate value="2017-01-30T15:50:00"/>
</current>

Find out more about date and time format using a UNIX Timestamp.

This API generates the a weather forecast report for the next 5 days with a 3 hour interval.
API Call

https://api.openweathermap.org/data/2.5/forecast?q=Moscow&appid=...

Output

{
"cod":"200",
"message":0.0036,
"cnt":40,
"list":[{"dt":1485799200,"main":{"temp":261.45,"temp_min":259.086,"temp_max":261.45,"pressure":1023.48,"sea_level":1045.39,"grnd_level":1023.48,"humidity":79,"temp_kf":2.37},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"02n"}],"clouds":{"all":8},"wind":{"speed":4.77,"deg":232.505},"snow":{},"sys":{"pod":"n"},"dt_txt":"2017-01-30 18:00:00"},
{"dt":1485810000,"main":{"temp":261.41,"temp_min":259.638,"temp_max":261.41,"pressure":1022.41,"sea_level":1044.35,"grnd_level":1022.41,"humidity":76,"temp_kf":1.78},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":32},"wind":{"speed":4.76,"deg":240.503},"snow":{"3h":0.011},"sys":{"pod":"n"},"dt_txt":"2017-01-30 21:00:00"},
{"dt":1485820800,"main":{"temp":261.76,"temp_min":260.571,"temp_max":261.76,"pressure":1021.34,"sea_level":1043.21,"grnd_level":1021.34,"humidity":84,"temp_kf":1.18},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":68},"wind":{"speed":4.71,"deg":243},"snow":{"3h":0.058},"sys":{"pod":"n"},"dt_txt":"2017-01-31 00:00:00"},
{"dt":1485831600,"main":{"temp":261.46,"temp_min":260.865,"temp_max":261.46,"pressure":1019.95,"sea_level":1041.79,"grnd_level":1019.95,"humidity":82,"temp_kf":0.59},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":68},"wind":{"speed":4.46,"deg":244.5},"snow":{"3h":0.05225},"sys":{"pod":"n"},"dt_txt":"2017-01-31 03:00:00"},
{"dt":1485842400,"main":{"temp":260.981,"temp_min":260.981,"temp_max":260.981,"pressure":1018.96,"sea_level":1040.84,"grnd_level":1018.96,"humidity":81,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13d"}],"clouds":{"all":80},"wind":{"speed":4.21,"deg":245.005},"snow":{"3h":0.19625},"sys":{"pod":"d"},"dt_txt":"2017-01-31 06:00:00"},
{"dt":1485853200,"main":{"temp":262.308,"temp_min":262.308,"temp_max":262.308,"pressure":1018.1,"sea_level":1039.77,"grnd_level":1018.1,"humidity":91,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13d"}],"clouds":{"all":88},"wind":{"speed":4.1,"deg":249.006},"snow":{"3h":0.535},"sys":{"pod":"d"},"dt_txt":"2017-01-31 09:00:00"},
{"dt":1485864000,"main":{"temp":263.76,"temp_min":263.76,"temp_max":263.76,"pressure":1016.86,"sea_level":1038.4,"grnd_level":1016.86,"humidity":87,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13d"}],"clouds":{"all":68},"wind":{"speed":3.87,"deg":254.5},"snow":{"3h":0.21},"sys":{"pod":"d"},"dt_txt":"2017-01-31 12:00:00"},
{"dt":1485874800,"main":{"temp":264.182,"temp_min":264.182,"temp_max":264.182,"pressure":1016.19,"sea_level":1037.77,"grnd_level":1016.19,"humidity":89,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":76},"wind":{"speed":3.67,"deg":257.001},"snow":{"3h":0.1375},"sys":{"pod":"n"},"dt_txt":"2017-01-31 15:00:00"},
{"dt":1485885600,"main":{"temp":264.67,"temp_min":264.67,"temp_max":264.67,"pressure":1015.32,"sea_level":1036.94,"grnd_level":1015.32,"humidity":86,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":88},"wind":{"speed":3.61,"deg":262.503},"snow":{"3h":0.1425},"sys":{"pod":"n"},"dt_txt":"2017-01-31 18:00:00"},
{"dt":1485896400,"main":{"temp":265.436,"temp_min":265.436,"temp_max":265.436,"pressure":1014.27,"sea_level":1035.76,"grnd_level":1014.27,"humidity":90,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":80},"wind":{"speed":3.67,"deg":266.5},"snow":{"3h":0.1625},"sys":{"pod":"n"},"dt_txt":"2017-01-31 21:00:00"},
{"dt":1485907200,"main":{"temp":266.104,"temp_min":266.104,"temp_max":266.104,"pressure":1013.1,"sea_level":1034.62,"grnd_level":1013.1,"humidity":90,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":80},"wind":{"speed":3.81,"deg":269.004},"snow":{"3h":0.1025},"sys":{"pod":"n"},"dt_txt":"2017-02-01 00:00:00"},
{"dt":1485918000,"main":{"temp":266.904,"temp_min":266.904,"temp_max":266.904,"pressure":1011.96,"sea_level":1033.47,"grnd_level":1011.96,"humidity":89,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":76},"wind":{"speed":4.26,"deg":274.002},"snow":{"3h":0.12},"sys":{"pod":"n"},"dt_txt":"2017-02-01 03:00:00"},
{"dt":1485928800,"main":{"temp":268.102,"temp_min":268.102,"temp_max":268.102,"pressure":1011.23,"sea_level":1032.62,"grnd_level":1011.23,"humidity":89,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13d"}],"clouds":{"all":76},"wind":{"speed":4.4,"deg":283.501},"snow":{"3h":0.13},"sys":{"pod":"d"},"dt_txt":"2017-02-01 06:00:00"},
{"dt":1485939600,"main":{"temp":270.269,"temp_min":270.269,"temp_max":270.269,"pressure":1010.85,"sea_level":1032.1,"grnd_level":1010.85,"humidity":92,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13d"}],"clouds":{"all":64},"wind":{"speed":4.53,"deg":297.5},"snow":{"3h":0.1875},"sys":{"pod":"d"},"dt_txt":"2017-02-01 09:00:00"},
{"dt":1485950400,"main":{"temp":270.585,"temp_min":270.585,"temp_max":270.585,"pressure":1010.49,"sea_level":1031.65,"grnd_level":1010.49,"humidity":89,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13d"}],"clouds":{"all":76},"wind":{"speed":4.31,"deg":302.004},"snow":{"3h":0.065},"sys":{"pod":"d"},"dt_txt":"2017-02-01 12:00:00"},
{"dt":1485961200,"main":{"temp":269.661,"temp_min":269.661,"temp_max":269.661,"pressure":1010.22,"sea_level":1031.49,"grnd_level":1010.22,"humidity":89,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":68},"wind":{"speed":4.91,"deg":296.5},"snow":{"3h":0.0825},"sys":{"pod":"n"},"dt_txt":"2017-02-01 15:00:00"},
{"dt":1485972000,"main":{"temp":269.155,"temp_min":269.155,"temp_max":269.155,"pressure":1009.95,"sea_level":1031.3,"grnd_level":1009.95,"humidity":89,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":80},"wind":{"speed":5.7,"deg":310.501},"snow":{"3h":0.11},"sys":{"pod":"n"},"dt_txt":"2017-02-01 18:00:00"},
{"dt":1485982800,"main":{"temp":268.056,"temp_min":268.056,"temp_max":268.056,"pressure":1011.21,"sea_level":1032.49,"grnd_level":1011.21,"humidity":89,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":68},"wind":{"speed":5.56,"deg":333},"snow":{"3h":0.225},"sys":{"pod":"n"},"dt_txt":"2017-02-01 21:00:00"},
{"dt":1485993600,"main":{"temp":265.803,"temp_min":265.803,"temp_max":265.803,"pressure":1013.79,"sea_level":1035.06,"grnd_level":1013.79,"humidity":83,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":8},"wind":{"speed":4.8,"deg":355.004},"snow":{"3h":0.03},"sys":{"pod":"n"},"dt_txt":"2017-02-02 00:00:00"},
{"dt":1486004400,"main":{"temp":263.381,"temp_min":263.381,"temp_max":263.381,"pressure":1015.66,"sea_level":1037.16,"grnd_level":1015.66,"humidity":84,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":4.2,"deg":348.503},"snow":{},"sys":{"pod":"n"},"dt_txt":"2017-02-02 03:00:00"},
{"dt":1486015200,"main":{"temp":261.85,"temp_min":261.85,"temp_max":261.85,"pressure":1017.63,"sea_level":1039.22,"grnd_level":1017.63,"humidity":76,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":3.81,"deg":345.502},"snow":{},"sys":{"pod":"d"},"dt_txt":"2017-02-02 06:00:00"},
{"dt":1486026000,"main":{"temp":263.455,"temp_min":263.455,"temp_max":263.455,"pressure":1019.32,"sea_level":1040.84,"grnd_level":1019.32,"humidity":84,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":3.06,"deg":344.004},"snow":{},"sys":{"pod":"d"},"dt_txt":"2017-02-02 09:00:00"},
{"dt":1486036800,"main":{"temp":264.015,"temp_min":264.015,"temp_max":264.015,"pressure":1020.41,"sea_level":1041.88,"grnd_level":1020.41,"humidity":85,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":2.52,"deg":334.501},"snow":{},"sys":{"pod":"d"},"dt_txt":"2017-02-02 12:00:00"},
{"dt":1486047600,"main":{"temp":259.684,"temp_min":259.684,"temp_max":259.684,"pressure":1021.52,"sea_level":1043.21,"grnd_level":1021.52,"humidity":76,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":2.48,"deg":320.501},"snow":{"3h":0.0024999999999999},"sys":{"pod":"n"},"dt_txt":"2017-02-02 15:00:00"},
{"dt":1486058400,"main":{"temp":255.188,"temp_min":255.188,"temp_max":255.188,"pressure":1022.09,"sea_level":1044.09,"grnd_level":1022.09,"humidity":66,"temp_kf":0},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"clouds":{"all":24},"wind":{"speed":1.23,"deg":283.003},"snow":{},"sys":{"pod":"n"},"dt_txt":"2017-02-02 18:00:00"},
{"dt":1486069200,"main":{"temp":255.594,"temp_min":255.594,"temp_max":255.594,"pressure":1022.03,"sea_level":1044.12,"grnd_level":1022.03,"humidity":64,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":48},"wind":{"speed":1.22,"deg":244.502},"snow":{},"sys":{"pod":"n"},"dt_txt":"2017-02-02 21:00:00"},
{"dt":1486080000,"main":{"temp":256.96,"temp_min":256.96,"temp_max":256.96,"pressure":1021.8,"sea_level":1043.77,"grnd_level":1021.8,"humidity":66,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":44},"wind":{"speed":1.23,"deg":237.506},"snow":{},"sys":{"pod":"n"},"dt_txt":"2017-02-03 00:00:00"},
{"dt":1486090800,"main":{"temp":258.109,"temp_min":258.109,"temp_max":258.109,"pressure":1020.97,"sea_level":1042.99,"grnd_level":1020.97,"humidity":77,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":80},"wind":{"speed":1.21,"deg":234.502},"snow":{},"sys":{"pod":"n"},"dt_txt":"2017-02-03 03:00:00"},
{"dt":1486101600,"main":{"temp":259.533,"temp_min":259.533,"temp_max":259.533,"pressure":1020.56,"sea_level":1042.53,"grnd_level":1020.56,"humidity":76,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":68},"wind":{"speed":1.21,"deg":229.509},"snow":{},"sys":{"pod":"d"},"dt_txt":"2017-02-03 06:00:00"},
{"dt":1486112400,"main":{"temp":263.438,"temp_min":263.438,"temp_max":263.438,"pressure":1020.46,"sea_level":1042.15,"grnd_level":1020.46,"humidity":84,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":56},"wind":{"speed":1.51,"deg":242.503},"snow":{},"sys":{"pod":"d"},"dt_txt":"2017-02-03 09:00:00"},
{"dt":1486123200,"main":{"temp":264.228,"temp_min":264.228,"temp_max":264.228,"pressure":1019.58,"sea_level":1041.24,"grnd_level":1019.58,"humidity":89,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":56},"wind":{"speed":1.58,"deg":242.503},"snow":{},"sys":{"pod":"d"},"dt_txt":"2017-02-03 12:00:00"},
{"dt":1486134000,"main":{"temp":261.153,"temp_min":261.153,"temp_max":261.153,"pressure":1019.63,"sea_level":1041.42,"grnd_level":1019.63,"humidity":80,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":76},"wind":{"speed":1.21,"deg":198.501},"snow":{"3h":0.0049999999999999},"sys":{"pod":"n"},"dt_txt":"2017-02-03 15:00:00"},
{"dt":1486144800,"main":{"temp":258.818,"temp_min":258.818,"temp_max":258.818,"pressure":1020.18,"sea_level":1042.03,"grnd_level":1020.18,"humidity":73,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":64},"wind":{"speed":1.21,"deg":209.002},"snow":{},"sys":{"pod":"n"},"dt_txt":"2017-02-03 18:00:00"},
{"dt":1486155600,"main":{"temp":257.218,"temp_min":257.218,"temp_max":257.218,"pressure":1020.43,"sea_level":1042.38,"grnd_level":1020.43,"humidity":65,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":44},"wind":{"speed":1.17,"deg":194.501},"snow":{},"sys":{"pod":"n"},"dt_txt":"2017-02-03 21:00:00"},
{"dt":1486166400,"main":{"temp":255.782,"temp_min":255.782,"temp_max":255.782,"pressure":1020.57,"sea_level":1042.75,"grnd_level":1020.57,"humidity":73,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":56},"wind":{"speed":1.21,"deg":175.001},"snow":{},"sys":{"pod":"n"},"dt_txt":"2017-02-04 00:00:00"},
{"dt":1486177200,"main":{"temp":254.819,"temp_min":254.819,"temp_max":254.819,"pressure":1020.99,"sea_level":1043.11,"grnd_level":1020.99,"humidity":68,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":44},"wind":{"speed":1.22,"deg":122.001},"snow":{"3h":0.0049999999999999},"sys":{"pod":"n"},"dt_txt":"2017-02-04 03:00:00"},
{"dt":1486188000,"main":{"temp":257.488,"temp_min":257.488,"temp_max":257.488,"pressure":1021.31,"sea_level":1043.48,"grnd_level":1021.31,"humidity":63,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13d"}],"clouds":{"all":68},"wind":{"speed":2.13,"deg":155.501},"snow":{"3h":0.04},"sys":{"pod":"d"},"dt_txt":"2017-02-04 06:00:00"},
{"dt":1486198800,"main":{"temp":259.827,"temp_min":259.827,"temp_max":259.827,"pressure":1021.81,"sea_level":1043.67,"grnd_level":1021.81,"humidity":90,"temp_kf":0},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13d"}],"clouds":{"all":68},"wind":{"speed":2.07,"deg":170.005},"snow":{"3h":0.03},"sys":{"pod":"d"},"dt_txt":"2017-02-04 09:00:00"},
{"dt":1486209600,"main":{"temp":261.256,"temp_min":261.256,"temp_max":261.256,"pressure":1021.31,"sea_level":1043.05,"grnd_level":1021.31,"humidity":86,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":76},"wind":{"speed":2.32,"deg":175.001},"snow":{"3h":0.0049999999999999},"sys":{"pod":"d"},"dt_txt":"2017-02-04 12:00:00"},
{"dt":1486220400,"main":{"temp":260.26,"temp_min":260.26,"temp_max":260.26,"pressure":1021,"sea_level":1042.96,"grnd_level":1021,"humidity":86,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":56},"wind":{"speed":2.47,"deg":180.501},"snow":{},"sys":{"pod":"n"},"dt_txt":"2017-02-04 15:00:00"}],"city":{"id":524901,"name":"Moscow","coord":{"lat":55.7522,"lon":37.6156},"country":"none"}}

Find out more about date and time format using a UNIX Timestamp.

This API generates the a weather forecast report for the next 5 days with a 3 hour interval.
API Call

https://api.openweathermap.org/data/2.5/forecast?q=Moscow&mode=xml&appid=...

Output

<weatherdata>
<location>
<name>London</name>
<type/>
<country>US</country>
<timezone/>
<location altitude="0" latitude="39.8865" longitude="-83.4483" geobase="geonames" geobaseid="4517009"/>
</location>
<credit/>
<meta>
<lastupdate/>
<calctime>0.0028</calctime>
<nextupdate/>
</meta>
<sun rise="2017-03-03T12:03:03" set="2017-03-03T23:28:37"/>
<forecast>
<time from="2017-03-03T06:00:00" to="2017-03-03T09:00:00">
<symbol number="600" name="light snow" var="13n"/>
<precipitation unit="3h" value="0.03125" type="snow"/>
<windDirection deg="303.004" code="WNW" name="West-northwest"/>
<windSpeed mps="2.29" name="Light breeze"/>
<temperature unit="kelvin" value="269.91" min="269.91" max="270.877"/>
<pressure unit="hPa" value="1005.61"/>
<humidity value="93" unit="%"/>
<clouds value="scattered clouds" all="32" unit="%"/>
</time>
<time from="2017-03-03T09:00:00" to="2017-03-03T12:00:00">
<symbol number="800" name="clear sky" var="01n"/>
<precipitation unit="3h" value="0.0225" type="snow"/>
<windDirection deg="293.503" code="WNW" name="West-northwest"/>
<windSpeed mps="3.55" name="Gentle Breeze"/>
<temperature unit="kelvin" value="269.23" min="269.23" max="269.957"/>
<pressure unit="hPa" value="1007.39"/>
<humidity value="90" unit="%"/>
<clouds value="scattered clouds" all="36" unit="%"/>
</time>
<time from="2017-03-03T12:00:00" to="2017-03-03T15:00:00">
<symbol number="800" name="clear sky" var="01d"/>
<precipitation unit="3h" value="0.0125" type="snow"/>
<windDirection deg="301.5" code="WNW" name="West-northwest"/>
<windSpeed mps="6.26" name="Moderate breeze"/>
<temperature unit="kelvin" value="270.93" min="270.93" max="271.416"/>
<pressure unit="hPa" value="1009.81"/>
<humidity value="100" unit="%"/>
<clouds value="few clouds" all="24" unit="%"/>
</time>
<time from="2017-03-03T15:00:00" to="2017-03-03T18:00:00">
<symbol number="800" name="clear sky" var="01d"/>
<precipitation unit="3h" value="0.0025" type="snow"/>
<windDirection deg="302.005" code="WNW" name="West-northwest"/>
<windSpeed mps="7.31" name="Moderate breeze"/>
<temperature unit="kelvin" value="272.25" min="272.25" max="272.491"/>
<pressure unit="hPa" value="1011.51"/>
<humidity value="92" unit="%"/>
<clouds value="scattered clouds" all="32" unit="%"/>
</time>
<time from="2017-03-03T18:00:00" to="2017-03-03T21:00:00">
<symbol number="800" name="clear sky" var="02d"/>
<precipitation/>
<windDirection deg="298.5" code="WNW" name="West-northwest"/>
<windSpeed mps="6.61" name="Moderate breeze"/>
<temperature unit="kelvin" value="272.817" min="272.817" max="272.817"/>
<pressure unit="hPa" value="1012.1"/>
<humidity value="79" unit="%"/>
<clouds value="clear sky" all="8" unit="%"/>
</time>
<time from="2017-03-03T21:00:00" to="2017-03-04T00:00:00">
<symbol number="800" name="clear sky" var="01n"/>
<precipitation/>
<windDirection deg="294.502" code="WNW" name="West-northwest"/>
<windSpeed mps="4.26" name="Gentle Breeze"/>
<temperature unit="kelvin" value="270.438" min="270.438" max="270.438"/>
<pressure unit="hPa" value="1012.92"/>
<humidity value="65" unit="%"/>
<clouds value="clear sky" all="0" unit="%"/>
</time>
<time from="2017-03-04T00:00:00" to="2017-03-04T03:00:00">
<symbol number="800" name="clear sky" var="01n"/>
<precipitation/>
<windDirection deg="292" code="WNW" name="West-northwest"/>
<windSpeed mps="2.66" name="Light breeze"/>
<temperature unit="kelvin" value="268.016" min="268.016" max="268.016"/>
<pressure unit="hPa" value="1013.34"/>
<humidity value="66" unit="%"/>
<clouds value="clear sky" all="0" unit="%"/>
</time>
<time from="2017-03-04T03:00:00" to="2017-03-04T06:00:00">
<symbol number="801" name="few clouds" var="02n"/>
<precipitation/>
<windDirection deg="290.001" code="WNW" name="West-northwest"/>
<windSpeed mps="1.42" name="Calm"/>
<temperature unit="kelvin" value="267.082" min="267.082" max="267.082"/>
<pressure unit="hPa" value="1013.88"/>
<humidity value="71" unit="%"/>
<clouds value="few clouds" all="20" unit="%"/>
</time>
<time from="2017-03-04T06:00:00" to="2017-03-04T09:00:00">
<symbol number="802" name="scattered clouds" var="03n"/>
<precipitation/>
<windDirection deg="344.003" code="NNW" name="North-northeast"/>
<windSpeed mps="1.32" name="Calm"/>
<temperature unit="kelvin" value="268.057" min="268.057" max="268.057"/>
<pressure unit="hPa" value="1013.66"/>
<humidity value="70" unit="%"/>
<clouds value="scattered clouds" all="44" unit="%"/>
</time>
<time from="2017-03-04T09:00:00" to="2017-03-04T12:00:00">
<symbol number="600" name="light snow" var="13n"/>
<precipitation unit="3h" value="0.13" type="snow"/>
<windDirection deg="143.001" code="SE" name="SouthEast"/>
<windSpeed mps="1.91" name="Light breeze"/>
<temperature unit="kelvin" value="268.687" min="268.687" max="268.687"/>
<pressure unit="hPa" value="1014.24"/>
<humidity value="78" unit="%"/>
<clouds value="broken clouds" all="80" unit="%"/>
</time>
<time from="2017-03-04T12:00:00" to="2017-03-04T15:00:00">
<symbol number="804" name="overcast clouds" var="04d"/>
<precipitation/>
<windDirection deg="136.502" code="SE" name="SouthEast"/>
<windSpeed mps="3.16" name="Light breeze"/>
<temperature unit="kelvin" value="270.296" min="270.296" max="270.296"/>
<pressure unit="hPa" value="1014.65"/>
<humidity value="85" unit="%"/>
<clouds value="overcast clouds" all="92" unit="%"/>
</time>
<time from="2017-03-04T15:00:00" to="2017-03-04T18:00:00">
<symbol number="600" name="light snow" var="13d"/>
<precipitation unit="3h" value="0.835" type="snow"/>
<windDirection deg="130.504" code="SE" name="SouthEast"/>
<windSpeed mps="4.16" name="Gentle Breeze"/>
<temperature unit="kelvin" value="273.066" min="273.066" max="273.066"/>
<pressure unit="hPa" value="1012.99"/>
<humidity value="88" unit="%"/>
<clouds value="few clouds" all="20" unit="%"/>
</time>
<time from="2017-03-04T18:00:00" to="2017-03-04T21:00:00">
<symbol number="800" name="clear sky" var="01d"/>
<precipitation/>
<windDirection deg="143.5" code="SE" name="SouthEast"/>
<windSpeed mps="2.77" name="Light breeze"/>
<temperature unit="kelvin" value="276.767" min="276.767" max="276.767"/>
<pressure unit="hPa" value="1011.06"/>
<humidity value="84" unit="%"/>
<clouds value="clear sky" all="0" unit="%"/>
</time>
<time from="2017-03-04T21:00:00" to="2017-03-05T00:00:00">
<symbol number="800" name="clear sky" var="01n"/>
<precipitation/>
<windDirection deg="89.5023" code="E" name="East"/>
<windSpeed mps="3.73" name="Gentle Breeze"/>
<temperature unit="kelvin" value="274.492" min="274.492" max="274.492"/>
<pressure unit="hPa" value="1010.42"/>
<humidity value="70" unit="%"/>
<clouds value="clear sky" all="0" unit="%"/>
</time>
<time from="2017-03-05T00:00:00" to="2017-03-05T03:00:00">
<symbol number="800" name="clear sky" var="01n"/>
<precipitation/>
<windDirection deg="97.5005" code="E" name="East"/>
<windSpeed mps="4.97" name="Gentle Breeze"/>
<temperature unit="kelvin" value="271.485" min="271.485" max="271.485"/>
<pressure unit="hPa" value="1011.31"/>
<humidity value="72" unit="%"/>
<clouds value="clear sky" all="0" unit="%"/>
</time>
<time from="2017-03-05T03:00:00" to="2017-03-05T06:00:00">
<symbol number="800" name="clear sky" var="01n"/>
<precipitation/>
<windDirection deg="107.002" code="ESE" name="East-southeast"/>
<windSpeed mps="4.67" name="Gentle Breeze"/>
<temperature unit="kelvin" value="270.202" min="270.202" max="270.202"/>
<pressure unit="hPa" value="1011.33"/>
<humidity value="72" unit="%"/>
<clouds value="clear sky" all="0" unit="%"/>
</time>
<time from="2017-03-05T06:00:00" to="2017-03-05T09:00:00">
<symbol number="800" name="clear sky" var="01n"/>
<precipitation/>
<windDirection deg="116.504" code="ESE" name="East-southeast"/>
<windSpeed mps="4.57" name="Gentle Breeze"/>
<temperature unit="kelvin" value="270.002" min="270.002" max="270.002"/>
<pressure unit="hPa" value="1010.53"/>
<humidity value="77" unit="%"/>
<clouds value="clear sky" all="0" unit="%"/>
</time>
<time from="2017-03-05T09:00:00" to="2017-03-05T12:00:00">
<symbol number="800" name="clear sky" var="01d"/>
<precipitation/>
<windDirection deg="127.003" code="SE" name="SouthEast"/>
<windSpeed mps="4.56" name="Gentle Breeze"/>
<temperature unit="kelvin" value="270.017" min="270.017" max="270.017"/>
<pressure unit="hPa" value="1010.21"/>
<humidity value="73" unit="%"/>
<clouds value="clear sky" all="0" unit="%"/>
</time>
<time from="2017-03-05T12:00:00" to="2017-03-05T15:00:00">
<symbol number="800" name="clear sky" var="01d"/>
<precipitation/>
<windDirection deg="148.002" code="SSE" name="South-southeast"/>
<windSpeed mps="4.68" name="Gentle Breeze"/>
<temperature unit="kelvin" value="276.199" min="276.199" max="276.199"/>
<pressure unit="hPa" value="1010.18"/>
<humidity value="81" unit="%"/>
<clouds value="clear sky" all="0" unit="%"/>
</time>
<time from="2017-03-05T15:00:00" to="2017-03-05T18:00:00">
<symbol number="800" name="clear sky" var="01d"/>
<precipitation/>
<windDirection deg="174.5" code="S" name="South"/>
<windSpeed mps="4.72" name="Gentle Breeze"/>
<temperature unit="kelvin" value="284.031" min="284.031" max="284.031"/>
<pressure unit="hPa" value="1008.28"/>
<humidity value="80" unit="%"/>
<clouds value="clear sky" all="0" unit="%"/>
</time>
<time from="2017-03-05T18:00:00" to="2017-03-05T21:00:00">
<symbol number="802" name="scattered clouds" var="03d"/>
<precipitation/>
<windDirection deg="207.501" code="SSW" name="South-southwest"/>
<windSpeed mps="5.02" name="Gentle Breeze"/>
<temperature unit="kelvin" value="286.276" min="286.276" max="286.276"/>
<pressure unit="hPa" value="1005.92"/>
<humidity value="71" unit="%"/>
<clouds value="scattered clouds" all="32" unit="%"/>
</time>
<time from="2017-03-05T21:00:00" to="2017-03-06T00:00:00">
<symbol number="802" name="scattered clouds" var="03n"/>
<precipitation/>
<windDirection deg="200.003" code="SSW" name="South-southwest"/>
<windSpeed mps="4.81" name="Gentle Breeze"/>
<temperature unit="kelvin" value="282.168" min="282.168" max="282.168"/>
<pressure unit="hPa" value="1005.45"/>
<humidity value="64" unit="%"/>
<clouds value="scattered clouds" all="44" unit="%"/>
</time>
<time from="2017-03-06T00:00:00" to="2017-03-06T03:00:00">
<symbol number="800" name="clear sky" var="01n"/>
<precipitation/>
<windDirection deg="201.001" code="SSW" name="South-southwest"/>
<windSpeed mps="5.37" name="Gentle Breeze"/>
<temperature unit="kelvin" value="279.202" min="279.202" max="279.202"/>
<pressure unit="hPa" value="1005.45"/>
<humidity value="68" unit="%"/>
<clouds value="clear sky" all="0" unit="%"/>
</time>
<time from="2017-03-06T03:00:00" to="2017-03-06T06:00:00">
<symbol number="802" name="scattered clouds" var="03n"/>
<precipitation/>
<windDirection deg="201.001" code="SSW" name="South-southwest"/>
<windSpeed mps="5.21" name="Gentle Breeze"/>
<temperature unit="kelvin" value="278.025" min="278.025" max="278.025"/>
<pressure unit="hPa" value="1005.18"/>
<humidity value="72" unit="%"/>
<clouds value="scattered clouds" all="44" unit="%"/>
</time>
<time from="2017-03-06T06:00:00" to="2017-03-06T09:00:00">
<symbol number="803" name="broken clouds" var="04n"/>
<precipitation/>
<windDirection deg="203.503" code="SSW" name="South-southwest"/>
<windSpeed mps="5.42" name=""/>
<temperature unit="kelvin" value="278.123" min="278.123" max="278.123"/>
<pressure unit="hPa" value="1004.75"/>
<humidity value="74" unit="%"/>
<clouds value="broken clouds" all="76" unit="%"/>
</time>
<time from="2017-03-06T09:00:00" to="2017-03-06T12:00:00">
<symbol number="804" name="overcast clouds" var="04d"/>
<precipitation/>
<windDirection deg="202.003" code="SSW" name="South-southwest"/>
<windSpeed mps="5.41" name=""/>
<temperature unit="kelvin" value="278.704" min="278.704" max="278.704"/>
<pressure unit="hPa" value="1004.96"/>
<humidity value="74" unit="%"/>
<clouds value="overcast clouds" all="92" unit="%"/>
</time>
<time from="2017-03-06T12:00:00" to="2017-03-06T15:00:00">
<symbol number="802" name="scattered clouds" var="03d"/>
<precipitation/>
<windDirection deg="193.502" code="SSW" name="South-southwest"/>
<windSpeed mps="6.01" name="Moderate breeze"/>
<temperature unit="kelvin" value="282.402" min="282.402" max="282.402"/>
<pressure unit="hPa" value="1004.49"/>
<humidity value="74" unit="%"/>
<clouds value="scattered clouds" all="48" unit="%"/>
</time>
<time from="2017-03-06T15:00:00" to="2017-03-06T18:00:00">
<symbol number="500" name="light rain" var="10d"/>
<precipitation unit="3h" value="0.02" type="rain"/>
<windDirection deg="203" code="SSW" name="South-southwest"/>
<windSpeed mps="9.16" name="Fresh Breeze"/>
<temperature unit="kelvin" value="287.36" min="287.36" max="287.36"/>
<pressure unit="hPa" value="1002.21"/>
<humidity value="76" unit="%"/>
<clouds value="few clouds" all="24" unit="%"/>
</time>
<time from="2017-03-06T18:00:00" to="2017-03-06T21:00:00">
<symbol number="804" name="overcast clouds" var="04d"/>
<precipitation/>
<windDirection deg="202.501" code="SSW" name="South-southwest"/>
<windSpeed mps="8.72" name="Fresh Breeze"/>
<temperature unit="kelvin" value="288.081" min="288.081" max="288.081"/>
<pressure unit="hPa" value="1000.08"/>
<humidity value="74" unit="%"/>
<clouds value="overcast clouds" all="88" unit="%"/>
</time>
<time from="2017-03-06T21:00:00" to="2017-03-07T00:00:00">
<symbol number="500" name="light rain" var="10n"/>
<precipitation unit="3h" value="0.51" type="rain"/>
<windDirection deg="187.001" code="S" name="South"/>
<windSpeed mps="7.01" name="Moderate breeze"/>
<temperature unit="kelvin" value="286.823" min="286.823" max="286.823"/>
<pressure unit="hPa" value="999.09"/>
<humidity value="76" unit="%"/>
<clouds value="overcast clouds" all="92" unit="%"/>
</time>
<time from="2017-03-07T00:00:00" to="2017-03-07T03:00:00">
<symbol number="804" name="overcast clouds" var="04n"/>
<precipitation/>
<windDirection deg="192" code="SSW" name="South-southwest"/>
<windSpeed mps="9.06" name="Fresh Breeze"/>
<temperature unit="kelvin" value="286.627" min="286.627" max="286.627"/>
<pressure unit="hPa" value="998.08"/>
<humidity value="72" unit="%"/>
<clouds value="overcast clouds" all="92" unit="%"/>
</time>
<time from="2017-03-07T03:00:00" to="2017-03-07T06:00:00">
<symbol number="804" name="overcast clouds" var="04n"/>
<precipitation/>
<windDirection deg="200.502" code="SSW" name="South-southwest"/>
<windSpeed mps="10.06" name="Fresh Breeze"/>
<temperature unit="kelvin" value="286.38" min="286.38" max="286.38"/>
<pressure unit="hPa" value="997.51"/>
<humidity value="76" unit="%"/>
<clouds value="overcast clouds" all="92" unit="%"/>
</time>
<time from="2017-03-07T06:00:00" to="2017-03-07T09:00:00">
<symbol number="804" name="overcast clouds" var="04n"/>
<precipitation/>
<windDirection deg="204.501" code="SSW" name="South-southwest"/>
<windSpeed mps="9.36" name="Fresh Breeze"/>
<temperature unit="kelvin" value="286.222" min="286.222" max="286.222"/>
<pressure unit="hPa" value="996.68"/>
<humidity value="88" unit="%"/>
<clouds value="overcast clouds" all="92" unit="%"/>
</time>
<time from="2017-03-07T09:00:00" to="2017-03-07T12:00:00">
<symbol number="501" name="moderate rain" var="10d"/>
<precipitation unit="3h" value="3.65" type="rain"/>
<windDirection deg="201.5" code="SSW" name="South-southwest"/>
<windSpeed mps="8.81" name="Fresh Breeze"/>
<temperature unit="kelvin" value="286.035" min="286.035" max="286.035"/>
<pressure unit="hPa" value="996.61"/>
<humidity value="95" unit="%"/>
<clouds value="overcast clouds" all="92" unit="%"/>
</time>
<time from="2017-03-07T12:00:00" to="2017-03-07T15:00:00">
<symbol number="804" name="overcast clouds" var="04d"/>
<precipitation/>
<windDirection deg="202.001" code="SSW" name="South-southwest"/>
<windSpeed mps="8.87" name="Fresh Breeze"/>
<temperature unit="kelvin" value="286.965" min="286.965" max="286.965"/>
<pressure unit="hPa" value="995.94"/>
<humidity value="96" unit="%"/>
<clouds value="overcast clouds" all="92" unit="%"/>
</time>
<time from="2017-03-07T15:00:00" to="2017-03-07T18:00:00">
<symbol number="804" name="overcast clouds" var="04d"/>
<precipitation/>
<windDirection deg="211.507" code="SSW" name="South-southwest"/>
<windSpeed mps="7.86" name="Moderate breeze"/>
<temperature unit="kelvin" value="288.163" min="288.163" max="288.163"/>
<pressure unit="hPa" value="994.32"/>
<humidity value="98" unit="%"/>
<clouds value="overcast clouds" all="92" unit="%"/>
</time>
<time from="2017-03-07T18:00:00" to="2017-03-07T21:00:00">
<symbol number="804" name="overcast clouds" var="04d"/>
<precipitation/>
<windDirection deg="229.5" code="SW" name="Southwest"/>
<windSpeed mps="7.46" name="Moderate breeze"/>
<temperature unit="kelvin" value="288.788" min="288.788" max="288.788"/>
<pressure unit="hPa" value="993.15"/>
<humidity value="100" unit="%"/>
<clouds value="overcast clouds" all="88" unit="%"/>
</time>
</forecast>
</weatherdata>

Find out more about date and time format using a UNIX Timestamp.

Tagged with: , ,

Currency Converter

currenciesOur aim is to create a currency converter to help us convert a sum of money from one currency to another.

Currency exchange rates are constantly changing which is why we have decided against the idea of storing all the exchanges rates in our code are these would not remain up-to-date. Instead we will retrieve up-to-date currency exchange rates by making calls to an API that provides the current rates.

To do so we will use the “Currency Converter API” to retrieve up-to-date exchange rates. You can read more about this API on: https://currencyconverterapi.com/. For the purpose of this blog post we will use the free version of this API.

This API works as follows:

API Request: e.g. Converting from US Dollars (USD) to British Pounds (GBP)

https://free.currencyconverterapi.com/api/v7/convert?q=USD_GBP&compact=y

JSON Output

{"USD_GBP":{"val":0.786905}}

This API uses JSON to format the data. JSON (JavaScript Object Notation) is a popular lightweight data-interchange format. Its main benefit is that it is easy for humans to read and write and it is easy for machines to parse and generate as you can see in the code provided below. You can read more about JSON on https://www.json.org/

Python Code


Check our code to see how we make a call to the API and how we retrieve and extract the requested JSON data.

Before running the code below, you will need to
request a free API key from currencyconvertapi.com
and insert this key on line 5 of the code below. Make sure you also follow instructions on how to verify your email to complete the API key request.

Your Task


Update the code above to accept a full range of currencies. You will need to use the API to retrieve a full list of currencies by making a request using the following URL: https://free.currencyconverterapi.com/api/v6/currencies

You will have to parse this JSON data to retrieve all the currency codes and append these to the list called validCurrencies currently declared on line 5 of the above trinket.

You may also want to output all the currency codes and the name of each currency to inform the user of the available codes and their meaning.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: ,

Real-Time ISS Tracker

international-space-station
The International Space Station (ISS) is moving at close to 28,000 km/h and orbits the Earth 16 times per day, once every 90 minutes! In this python challenge we are going to use an open source API (Open Notify) to retrieve some real-time data from Nasa about the location of the ISS.

Our aim is to retrieve the current longitude and latitude of the International Space Station and to use this information to plot it on the map.

You can read more about the API on: http://open-notify.org/Open-Notify-API/ISS-Location-Now/

Note that we will also use the Open Notify API to retrieve the current numbers of astronauts in space and to retrieve all their names and the spacecraft they are on. You can read more about this API on: http://open-notify.org/Open-Notify-API/People-In-Space/

Both these APIs use JSON to format the data. JSON (JavaScript Object Notation) is a popular lightweight data-interchange format. Its main benefit is that it is easy for humans to read and write and it is easy for machines to parse and generate as you can see in the code provided below. You can read more about JSON on https://www.json.org/

Python Code


Check our code to see how we make a call to the API and how we retrieve and extract the requested JSON data. You may need to see this trinket in full screen view to see the position of the ISS on the world map. An infinite “while True” loop is used to constantly update the position of the ISS on the map, with a 5-second delay between each iteration.

Your Task


The Open Notify API provides a third API to find out when the ISS will next pass over a specific location. The API requires you to provide the longitude and latitude of a location and returns a list of the next 5 date and time timestamps when the ISS will pass over, or closed to, this location.

You can find out more about this API on http://open-notify.org/Open-Notify-API/ISS-Pass-Times/

Your task is to write a Python script to display the date and time of the next five passes of the ISS over Paris, France (longitude: 45.51° N, latitude: 2.20° E).

Note that you will need to use the time library to convert a Unix Epoch Timestamp into a human readable format, using the following code:

import time
timestamp = 1547281745
datetime = time.strftime('%A, %Y-%m-%d %H:%M:%S', time.localtime(timestamp))
print(datetime)
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: ,

3D Snowman

In this blog post we will use Glowscript to create a 3D animation of a snowman.

Our aim is to create our snowman by adding different 3D shapes such as spheres, cylinders, cones, etc. We will then create a compound object to join these shapes together in a single object. Finally, we will use an infinite while loop to animate/rotate the snowman around the Y axis.

Glowscript/vPython?…


To complete this challenge and find out about all the 3D shapes you can use in Glowscript, you will need to refer to the Glowscript/vPython online documentation.

(x,y,z) Coordinates


Note that to complete this challenge you will need a good understanding of how 3D coordinates work:
xyz-axis

snowman-coordinates

Complete the code


We have started the code for you. Your task is to complete this code to customise this snowman further. (Use Google Chrome to preview this animation)


Right Click on the animation to change the view point (rotate camera angle).

Extension Task


snow-globeBuild a snow globe around your snowman. You will need to use an opacity argument when creating the glass sphere.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: ,

Target Detection Algorithm

targeting-computer-algorithmIn star wars movies, most spaceships are fitted with laser cannons to shoot enemy spaceships. To assist the pilot, these spaceships have built-in targeting computers that enable them to aim the cannon and inform them when their target is within reach. When this is the case, the algorithm informs the pilot with the following message:

target-acquired

We have retrieved the code used in a Star Wars Tie Fighter spaceship. The code is used to aim the laser cannon. However this spaceship is not fitted with a target acquisition algorithm to inform the pilot when to shoot.

star-wars-spaceship

Your aim is to upgrade this code to detect when the enemy spaceship is within reach of the laser cannon.

To do so you will need to check if the X, Y coordinates of the cannon aim (mouse pointer) is within the A B C triangle representing the enemy spaceship:
target-acquired-coordinates

Python Code


Your aim is to upgrade this code from line 60 to detect when the enemy spaceship is within reach of the laser cannon:


unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Periodic Table of Programming Concepts

This periodic table of programming concepts list the main concepts and techniques used in procedural programming. High level procedural programming languages such as Python, Visual Basic, C, etc. enable you to use most, if not all of these concepts in your code.

Click on the concepts below to reveal short definitions of each concept.

Programming Concepts – Periodic TableOpen in new tab/window

My Javascript Calculator

For this challenge, you will use your HTML, CSS and JavaScript to create a fully functional calculator as follows:
js-calculator

Before attemtping this challenge, make sure you gain a full understanding of how HTML, CSS and JavaScript are used on a web page and how these three client-side languages interact with each other by completing the following challenges:

HTML, CSS & JS Code


We have started the code for you. Click on the “Edit on Codepen” button to edit this code and implement your calculator.

See the Pen JS: Add String (with parseInt) by 101 Computing (@101Computing) on CodePen.

A Puzzling Algorithm

a-puzzling-algorithm
This algorithm is based on:
sequencing-label

Test Plan


To understand what this algorithm is meant to do, we will predict its expected output for different input values and record our predicted outputs in a test plan.

Test # Input Values Expected Output
#1 a = 7
b = 2
#1 a = 3
b = 9
#1 a = 150
b = 10

Now that you have completed the “expected output” column of this test plan you might be able to explain what this algorithm actually does?

You can now use our online Python IDE to implement this algorithm and complete each test from the above test plan.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Understanding Bitmap Pictures

resolution-and-colour-depthIn this blog post we are investigating what are bitmap pictures and how they are stored on a computer using binary code.

Bitmap Pictures?


Bitmap pictures (also called raster graphics) are computer graphics made of pixels of different colours. Pictures taken with a digital camera (or a scanner) are bitmap pictures. It is also possible to create bitmap pictures using software such as Paint, Photoshop or the Gimp.

.bmp, .tif, .png, .gif and .jpg are all file extensions for different types of bitmap pictures.

Bitmap Picture Quality


The qualify of a bitmap picture relies on mainly two criteria:

  • The resolution of the picture,
  • The colour depth of the picture.

Resolution


The quality of a picture is directly linked to the number of pixels in the picture. The number of pixels in a picture depends on the width, height and resolution of a picture.

  • The width and height of a picture can be given in pixels or inches.
  • The resolution of a picture is the number of pixels per inch and is measured in dpi (dots per inch) or ppi (pixels per inch).

A higher resolution picture contains a higher number of pixels which results in better quality but also a larger file size.

A higher resolution results in better quality pictures.

A higher resolution results in better quality pictures.

A typical resolution for a picture used on a website would be 72 ppi.
For printing purposes, high quality printing would require a higher resolution (e.g 200 ppi, 300 ppi or even 600 ppi).

A higher resolution picture can be enlarged (zoom in) and may still remain crisp whereas a lower resolution picture will look pixelated when enlarged. So when taking pictures with a smartphone or a digital camera, it is important to consider what will the picture be used for. If the intention is to print large canvas of a picture, it will need to be saved using the highest resolution settings, even though it will take more storage space on the device.

color-depth

Colour Depth


The Colour depth (or color depth – american spelling) of a picture corresponds to the number of bits used to represent the colour value of a single pixel.

Let’s look at the following pixel art widgets below. They are all based on a different colour depths varying from 1 bit per pixel to 4 bits per pixel.

Colour Depth: 1 bit per pixel2 bits per pixel3 bits per pixel4 bits per pixel

A you can see a pictue with a higher colour depth uses a higher number of bits per pixel which results in a wider range of colours hence better quality but also a larger file size.

Most bitmap graphics you would find on the web (especially .png or .jpg) would use a colour depth of 24 bits, resulting in a colour palette of 224 (more than 16,000,000) colours.

The RGB colour coding system uses such a colour depth using 3 Bytes = 24 bits per pixel.

Let’s recap…


Complete this drag and drop activity to highlight the key concepts of bitmap graphics.

dpi
pixels
depth
quality
colours
raster
bits
file size
resolution
pixelate
higher
inch

Bitmap pictures, resolution & colour depth

  • Bitmap pictures are also known as graphics and are made of of different colours.
  • The two main factors which affect the quality of a bitmap picture are and colour depth.
  • The resolution is the number of pixels per , measured in dots per inch () or pixels per inch (ppi).
  • The higher the resolution the better the of the picture. A picture with a low resolution will when the picture is enlarged.
  • The colour is the number of per pixel.
  • The the colour depth, the wider the range of available, hence the higher the quality of the picture, and the larger the .

The Pizzaiolo’s Puzzle

PIZZAA pizzaiolo (a man who makes pizza) has been asked to produce a very large pizza, to sprinkle some Parmesan cheese evenly on the pizza and to spread a full jar of black olives (approximately 80 olives) on the pizza.

He has decided to find a method to evenly spread the olives on the pizza to ensure that:

  • the olives cover the entire pizza,
  • the olives are relatively equidistant from each others,

Fermat’s Spiral & Vogel’s Model


After doing some research online, our pizzaiolo came across the following webpage about Fermat’s Spiral, and was captivated to find out about how the Vogel’s model could be used to calculate the polar coordinates of each olive to be added to his pizza:

Vogel's Model

  • Where θ is the angle,
  • r is the radius or distance from the centre,
  • n is the index number of the olive,
  • c is a constant scaling factor,
  • The angle 137.508° is the golden angle which is approximated by ratios of Fibonacci numbers.

Python Code


The following Python Turtle demonstrates how Vogel’s model can be used to solve our pizzaiolo’s puzzle:

Your Task


Update the code above to add extra ingredients to your pizza (e.g. pepperoni slices). Try different values instead of the golden angle to see the impact on the resulting pattern.
pizzas
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area