forked from arubatrainings1/test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab3.8-countries.py
25 lines (22 loc) · 1.07 KB
/
Lab3.8-countries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import json
import requests
import urllib3 # this disables warning about self-signed certs
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
url = 'https://restcountries.eu/rest/v2/all' # countries api
response = requests.get(url) # opening a network and fetching a data
print(response) # response object
print(response.status_code) # status code, success:200
countries = response.text
data_python=json.loads(countries) #transfer to python format so that later program can process the data.
country = input("enter the country you want to check, Capitalize the first letter: ")
for i in range(len(data_python)):
if data_python[i]["name"] == country:
print("Iceland is the number " + str(i)+ " in the countries list" )
print("The population is " + str(data_python[i]["population"]))
print(f'The population is {str(data_python[i]["population"])}') #f-string format
print(data_python[i])
break # quit from loop.
else:
i+=1
if i == len(data_python):
print("no this country")