├── .gitignore
├── Examples
├── data
│ ├── google.html
│ ├── input.csv
│ ├── input.txt
│ ├── output.txt
│ ├── requests.png
│ └── sample.html
├── example_10_authentication.py
├── example_11_rest_api.py
├── example_12_graphql_api.py
├── example_1_review.py
├── example_2_dictionaries.py
├── example_3_exceptions.py
├── example_3b_advanced_exceptions.py
├── example_4_read_file.py
├── example_5_write_file.py
├── example_6_csv_files.py
├── example_7_requests.py
├── example_8_beautiful_soup.py
└── example_9_download_image.py
├── Problems
├── Solutions
│ ├── data
│ │ ├── Z_countries.txt
│ │ ├── countries.txt
│ │ └── google.html
│ ├── problem_1_review.py
│ ├── problem_2_dictionaries.py
│ ├── problem_3_exceptions.py
│ ├── problem_4_files.py
│ ├── problem_4b_files_defaultdict.py
│ └── problem_5_beautiful_soup.py
├── data
│ ├── countries.txt
│ └── google.html
├── problem_1_review.py
├── problem_2_dictionaries.py
├── problem_3_exceptions.py
├── problem_4_files.py
└── problem_5_beautiful_soup.py
├── Project
├── Solutions
│ ├── a_print_to_txt
│ │ ├── countries.txt
│ │ └── scraper.py
│ ├── b_print_to_csv
│ │ ├── countries.csv
│ │ └── scraper.py
│ └── c_more_data
│ │ ├── countries_more.csv
│ │ └── scraper.py
├── UN_countries_full.html
├── UN_countries_simplified.html
└── scraper.py
├── README.md
├── docs
├── PATH_LOCATIONS.md
├── PyCharm_interpreter.md
├── WININSTALL.md
├── WINSETPATH.md
└── img
│ ├── installer_1.png
│ ├── installer_2.png
│ ├── installer_3.png
│ ├── pycharm_python_1.png
│ ├── pycharm_python_2.png
│ ├── pycharm_python_3a.png
│ ├── pycharm_python_3b.png
│ ├── pycharm_python_4.png
│ ├── pycharm_python_5a.png
│ └── pycharm_python_5b.png
└── requirements.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | *.egg-info/
24 | .installed.cfg
25 | *.egg
26 | MANIFEST
27 |
28 | # PyInstaller
29 | # Usually these files are written by a python script from a template
30 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 | *.manifest
32 | *.spec
33 |
34 | # Installer logs
35 | pip-log.txt
36 | pip-delete-this-directory.txt
37 |
38 | # Unit test / coverage reports
39 | htmlcov/
40 | .tox/
41 | .coverage
42 | .coverage.*
43 | .cache
44 | nosetests.xml
45 | coverage.xml
46 | *.cover
47 | .hypothesis/
48 | .pytest_cache/
49 |
50 | # Translations
51 | *.mo
52 | *.pot
53 |
54 | # Django stuff:
55 | *.log
56 | local_settings.py
57 | db.sqlite3
58 |
59 | # Flask stuff:
60 | instance/
61 | .webassets-cache
62 |
63 | # Scrapy stuff:
64 | .scrapy
65 |
66 | # Sphinx documentation
67 | docs/_build/
68 |
69 | # PyBuilder
70 | target/
71 |
72 | # Jupyter Notebook
73 | .ipynb_checkpoints
74 |
75 | # pyenv
76 | .python-version
77 |
78 | # celery beat schedule file
79 | celerybeat-schedule
80 |
81 | # SageMath parsed files
82 | *.sage.py
83 |
84 | # Environments
85 | .env
86 | .venv
87 | env/
88 | venv/
89 | ENV/
90 | env.bak/
91 | venv.bak/
92 |
93 | # Spyder project settings
94 | .spyderproject
95 | .spyproject
96 |
97 | # Rope project settings
98 | .ropeproject
99 |
100 | # mkdocs documentation
101 | /site
102 |
103 | # mypy
104 | .mypy_cache/
105 |
106 | .DS_Store
107 | .idea
108 | .vscode
109 |
--------------------------------------------------------------------------------
/Examples/data/google.html:
--------------------------------------------------------------------------------
1 |
Google
--------------------------------------------------------------------------------
/Examples/data/input.csv:
--------------------------------------------------------------------------------
1 | Name,Age
2 | Shehin,23
3 | Freddy,85
4 | Bob,5
5 | Gabriella,62
6 |
--------------------------------------------------------------------------------
/Examples/data/input.txt:
--------------------------------------------------------------------------------
1 | 2
2 | 25
3 | 637
4 | 86
5 | 947
6 | 5
7 | 627
8 | 46
9 | 36
10 |
--------------------------------------------------------------------------------
/Examples/data/output.txt:
--------------------------------------------------------------------------------
1 | abcda
2 | b
3 | c
4 | d
5 |
--------------------------------------------------------------------------------
/Examples/data/requests.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ariannedee/python-level-2/ed532c42bb2825529a438f8675dc16f2ca6eb756/Examples/data/requests.png
--------------------------------------------------------------------------------
/Examples/data/sample.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | The Dormouse's story
4 |
5 |
6 | The Dormouse's story
7 |
8 |
9 | Once upon a time there were three little sisters; and their names were
10 | Elsie,
11 | Lacie and
12 | Tillie;
13 | and they lived at the bottom of a well.
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Examples/example_10_authentication.py:
--------------------------------------------------------------------------------
1 | import requests
2 | from bs4 import BeautifulSoup
3 |
4 | LOGIN_URL = "https://github.com/session"
5 | USERNAME = "***"
6 | PASSWORD = "***"
7 |
8 | URL = "https://github.com"
9 | headers = {'User-Agent': f'Your name (your@email.com)'}
10 |
11 | # Create new session so that cookies are saved between requests
12 | session_requests = requests.session()
13 |
14 | # Get the authenticity token from the login page
15 | login_page = session_requests.get(LOGIN_URL, headers=headers)
16 | soup = BeautifulSoup(login_page.text, 'html.parser')
17 |
18 | # The input name might be different depending on the site. Inspect the form and look for a hidden input with "authenticity" or "csrf".
19 | authenticity_token = soup.find('input', attrs={'name': 'authenticity_token'}).get('value')
20 | print(authenticity_token)
21 |
22 | # Send login request
23 | data = {
24 | 'login': USERNAME,
25 | 'password': PASSWORD,
26 | 'authenticity_token': authenticity_token,
27 | }
28 | response = session_requests.post(LOGIN_URL, headers=headers, data=data)
29 | print(response.status_code)
30 |
31 | # Now you are authenticated and can start scraping the URL you want
32 | response = session_requests.get(URL, headers=headers)
33 |
34 | with open('data/logged_in.html', 'w') as file: # Open this to verify that your login worked
35 | file.write(response.text)
36 |
37 | # ... Do some scraping with the result
38 |
--------------------------------------------------------------------------------
/Examples/example_11_rest_api.py:
--------------------------------------------------------------------------------
1 | """
2 | Get repository data from Github's REST API.
3 | V3 REST API documentation: https://developer.github.com/v3/
4 | To generate an authentication token for your user, follow: https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line
5 | """
6 |
7 | import json
8 | import requests
9 | import sys
10 |
11 | BASE_URL = "https://api.github.com" # The root of all of our api requests
12 | URL = BASE_URL + '/user/repos' # The specific data we want
13 | headers = {
14 | 'Accept': 'application/vnd.github.v3+json',
15 | 'Content-Type': 'application/json',
16 | 'Authorization': 'token {Your token here}', # See https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line
17 | }
18 |
19 | # Make API request
20 | response = requests.get(URL, headers=headers)
21 |
22 | # Handle bad requests
23 | if response.status_code != 200:
24 | print(response.status_code)
25 | print(response.text)
26 | sys.exit()
27 |
28 | # Turn the response string into JSON data. Data is now a list of dictionaries representing repositories
29 | data = json.loads(response.text)
30 |
31 | # Or you can just use the json property.
32 | data = response.json()
33 |
34 | # Now do what you want with the data
35 | if len(data) > 0:
36 | # I want to list all of the attributes we can get from each repository
37 | print("Keys")
38 | for key in data[0].keys():
39 | print(' ' + key)
40 |
41 | # I also want to list each repository name
42 | print("\nRepository names")
43 | for repo in data:
44 | print(' ' + repo['full_name'])
45 |
--------------------------------------------------------------------------------
/Examples/example_12_graphql_api.py:
--------------------------------------------------------------------------------
1 | """
2 | Get repository data from Github's GraphQL API.
3 | V4 GraphQL API documentation: https://developer.github.com/v4/
4 | To generate an authentication token for your user, follow: https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line
5 | """
6 |
7 | import requests
8 | import sys
9 |
10 | API_URL = "https://api.github.com/graphql"
11 | headers = {
12 | 'Content-Type': 'application/json',
13 | 'Authorization': 'token {Your token here}', # See https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line
14 | }
15 |
16 | # Specify the data you want from the API, test at https://developer.github.com/v4/explorer
17 | query = """
18 | query {
19 | viewer {
20 | repositories(first:100) {
21 | totalCount
22 | nodes {
23 | nameWithOwner
24 | }
25 | }
26 | }
27 | }
28 | """
29 | # Send the query in the right format for GraphQL
30 | data = {"query": query}
31 | response = requests.post(API_URL, headers=headers, json=data)
32 |
33 | # Handle bad requests (e.g. not authenticated)
34 | if response.status_code != 200:
35 | print(response.status_code)
36 | print(response.text)
37 | sys.exit()
38 |
39 | # Turn the response string into JSON data. Data is now a list of dictionaries representing repositories
40 | response = response.json()
41 |
42 | # Handle bad queries (e.g. improperly formatted query string)
43 | if 'errors' in response:
44 | print(response['errors'])
45 | sys.exit()
46 |
47 | data = response['data']
48 | print(data)
49 |
50 | # Now do what you want with the data
51 | repos = data['viewer']['repositories']['nodes']
52 | if len(repos) > 0:
53 | # I want to list each repository name
54 | print("\nRepository names")
55 | for repo in repos:
56 | print(' ' + repo['nameWithOwner'])
57 |
--------------------------------------------------------------------------------
/Examples/example_1_review.py:
--------------------------------------------------------------------------------
1 | # Getting user input
2 | temp = int(input("What's the temperature? "))
3 |
4 |
5 | # Conditionals
6 | if temp <= 0:
7 | print("It’s freezing")
8 | elif temp >= 100:
9 | print("It’s boiling")
10 | else:
11 | print("It's alright")
12 |
13 |
14 | # Lists
15 | populous_countries = ["China", "India", "USA", "Indonesia", "Brazil"]
16 |
17 | populous_countries[2] = "United States"
18 | populous_countries.append("Pakistan")
19 |
20 |
21 | # For loop
22 | for i in range(10):
23 | print(i * i)
24 |
25 | # Import from module/library
26 | from time import sleep
27 |
28 |
29 | # While loop
30 | seconds_left = 3
31 |
32 | while seconds_left > 0:
33 | print(seconds_left)
34 | sleep(1)
35 | seconds_left -= 1
36 |
37 | print("Lift off!")
38 |
39 |
40 | # Functions
41 | def square(num):
42 | return num * num
43 |
44 |
45 | # Assertions
46 | assert square(10) == 100
47 |
--------------------------------------------------------------------------------
/Examples/example_2_dictionaries.py:
--------------------------------------------------------------------------------
1 | # Dictionaries as maps
2 | canadian_capitals = {
3 | 'AB': 'Edmonton',
4 | 'BC': 'Victoria',
5 | 'MB': 'Winnipeg',
6 | 'NB': 'Fredericton',
7 | 'NL': 'St. John\'s',
8 | 'NS': 'Halifax',
9 | 'NT': 'Yellowknife',
10 | 'NU': 'Iqaluit',
11 | 'ON': 'Toronto',
12 | 'PE': 'Charlottetown',
13 | 'QC': 'Quebec City',
14 | 'SK': 'Regina',
15 | 'YT': 'Whitehorse',
16 | }
17 |
18 | canadian_capitals.keys() # ['AB', 'BC', ...]
19 | canadian_capitals.values() # ['Edmonton', 'Victoria', ...]
20 |
21 | print(canadian_capitals['ON']) # Get an item
22 | del canadian_capitals['AB'] # Delete an item
23 | canadian_capitals['NU'] = 'Bob' # Update an item
24 | canadian_capitals['XX'] = 'New capital' # Add an item
25 | print(len(canadian_capitals)) # Get the length
26 |
27 | # Get value if the key exists, else return None
28 | print(canadian_capitals.get('AA'))
29 |
30 | # Get value if the key exists, else return a default value
31 | print(canadian_capitals.get('AA', 'N/A'))
32 |
33 | for code in canadian_capitals:
34 | print(f'The capital of {code} is {canadian_capitals[code]}')
35 |
36 | for capital in canadian_capitals.values():
37 | print(capital)
38 |
39 | for province, capital in canadian_capitals.items():
40 | print(f'The capital of {province} is {capital}')
41 |
42 | if 'YT' in canadian_capitals:
43 | print('Found key')
44 |
45 | if 'Victoria' in canadian_capitals.values():
46 | print('Found value')
47 |
48 | # Dictionaries as objects
49 | book_1 = {"title": "To Kill a Mockingbird", "author": "Harper Lee", "published_year": 1960}
50 | book_2 = {"title": "Jane Eyre", "author": "Charlotte Brontë", "published_year": 1847}
51 | book_3 = {"title": "1984", "author": "George Orwell", "published_year": 1949}
52 |
53 | books = [book_1, book_2, book_3]
54 |
55 | def book_sort_key(book):
56 | return book['published_year']
57 |
58 | books.sort(key=lambda book: book['published_year'])
59 |
60 | from pprint import pprint
61 | pprint(books)
62 |
--------------------------------------------------------------------------------
/Examples/example_3_exceptions.py:
--------------------------------------------------------------------------------
1 | try:
2 | int('five')
3 | print('Success!')
4 | except ValueError as e:
5 | print("Fail!")
6 | print(e)
7 |
8 |
9 | print('Got here')
10 |
11 | int('1.5') # Run fails with exit code 1
12 | print("Didn't get here")
13 |
--------------------------------------------------------------------------------
/Examples/example_3b_advanced_exceptions.py:
--------------------------------------------------------------------------------
1 | try:
2 | int('5')
3 | print('Success!')
4 | print(hi)
5 | except (ValueError, NameError) as e: # Catch multiple error types
6 | print("Fail!")
7 | print(e)
8 |
9 |
10 | try:
11 | int('5')
12 | print('Success!')
13 | print(hi)
14 | except ValueError: # Catch multiple error types with different behaviour
15 | print("Failure: Value error")
16 | except NameError:
17 | print("Failure: Name error")
18 | except Exception as e:
19 | print(repr(e))
20 |
21 |
22 | try:
23 | int('5')
24 | print('Success!')
25 | except ValueError:
26 | print("Fail!")
27 | else:
28 | print('Everything worked') # Runs after try block finishes without errors
29 | finally:
30 | print('This always happens') # Runs after everything, even if there was an error
31 |
32 |
33 | class MyCustomError(Exception):
34 | pass
35 |
36 |
37 | raise MyCustomError("Here's an error message")
38 |
--------------------------------------------------------------------------------
/Examples/example_4_read_file.py:
--------------------------------------------------------------------------------
1 | """
2 | Read a file with a number on each line. Print the sum of those numbers.
3 | """
4 | sum_ = 0
5 | with open('data/input.txt') as file:
6 | for line in file.readlines():
7 | sum_ += int(line)
8 |
9 | print(f"The sum was {sum_}")
10 |
--------------------------------------------------------------------------------
/Examples/example_5_write_file.py:
--------------------------------------------------------------------------------
1 |
2 | with open('data/output.txt', 'w') as file:
3 | lines = ['a', 'b', 'c', 'd']
4 | file.writelines(lines)
5 |
6 | for line in lines:
7 | file.write(line + '\n')
8 |
9 | file.write('\n'.join(lines))
10 |
--------------------------------------------------------------------------------
/Examples/example_6_csv_files.py:
--------------------------------------------------------------------------------
1 | import csv
2 |
3 | with open('data/input.csv', 'r') as file:
4 | reader = csv.DictReader(file)
5 |
6 | for person in reader:
7 | print(f'{person["Name"]} is {person["Age"]}')
8 |
--------------------------------------------------------------------------------
/Examples/example_7_requests.py:
--------------------------------------------------------------------------------
1 | import requests
2 |
3 | URL = "https://google.com"
4 |
5 | # Dictionary of HTTP headers
6 | headers = {'User-Agent': f'your@email.com'} # Metadata for request
7 | params = {'param1': 123, 'param2': 456} # Adds ?param1=123¶m2=456 to URL
8 |
9 | response = requests.get(URL, params=params, headers=headers)
10 |
11 | # Full list of HTTP status codes: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
12 | # Common status codes:
13 | # - 200 OK
14 | # - 401 Unauthorized
15 | # - 404 Not found
16 | # - 502 Bad gateway
17 | print(response.status_code)
18 | print(response.reason)
19 |
20 | # Raise exception if unsuccessful
21 | response.raise_for_status()
22 |
23 | # Get text contents
24 | print(response.text)
25 |
26 | with open('data/google.html', 'w', encoding="utf-8") as file:
27 | file.write(response.text)
28 |
--------------------------------------------------------------------------------
/Examples/example_8_beautiful_soup.py:
--------------------------------------------------------------------------------
1 | """
2 | Documentation: https://www.crummy.com/software/BeautifulSoup/bs4/doc/
3 | """
4 | from bs4 import BeautifulSoup
5 |
6 | with open('data/sample.html', 'r') as file:
7 | html_doc = file.read()
8 |
9 | soup = BeautifulSoup(html_doc, 'html.parser')
10 |
11 |
12 | # Print the HTML document with nesting and indentation
13 | print(soup.prettify(formatter='html'))
14 |
15 |
16 | # FINDING MULTIPLE ELEMENTS
17 |
18 | soup.find_all('a') # Find all elements (returns a list)
19 | soup.find_all('a', attrs={'class': 'sister'}) # Filter with attributes dict
20 | soup.find_all('a', class_='sister') # Filter with keyword arguments
21 | soup.find_all('a', string='Elsie') # Filter by content
22 |
23 |
24 | # FINDING A SINGLE ELEMENT
25 |
26 | soup.a # Get the first child element
27 | soup.find('a', attrs={'id': 'link1'}) # Filter with attributes dict
28 | soup.find('a', id='link1') # Filter with keyword arguments
29 | soup.find('a', string='Elsie') # Filter by content
30 |
31 |
32 | # GETTING DATA FROM AN ELEMENT
33 | link = soup.a
34 |
35 | link.string # Get text of an element (no nested content)
36 | link.text # Get text of an element (including nested content)
37 | link['href'] # Get attribute of an element (if it exists)
38 | link.get('href') # Get attribute (if it might not exist)
39 |
--------------------------------------------------------------------------------
/Examples/example_9_download_image.py:
--------------------------------------------------------------------------------
1 | import requests
2 | import shutil
3 |
4 | URL = "https://upload.wikimedia.org/wikipedia/commons/a/aa/Requests_Python_Logo.png"
5 | response = requests.get(URL, stream=True)
6 | if response.status_code == 200:
7 | with open('data/requests.png', 'wb') as f:
8 | response.raw.decode_content = True
9 | shutil.copyfileobj(response.raw, f)
10 |
--------------------------------------------------------------------------------
/Problems/Solutions/data/Z_countries.txt:
--------------------------------------------------------------------------------
1 | Zambia
2 | Zimbabwe
3 |
--------------------------------------------------------------------------------
/Problems/Solutions/data/countries.txt:
--------------------------------------------------------------------------------
1 | Afghanistan
2 | Albania
3 | Algeria
4 | Andorra
5 | Angola
6 | Antigua & Deps
7 | Argentina
8 | Armenia
9 | Australia
10 | Austria
11 | Azerbaijan
12 | Bahamas
13 | Bahrain
14 | Bangladesh
15 | Barbados
16 | Belarus
17 | Belgium
18 | Belize
19 | Benin
20 | Bhutan
21 | Bolivia
22 | Bosnia Herzegovina
23 | Botswana
24 | Brazil
25 | Brunei
26 | Bulgaria
27 | Burkina
28 | Burundi
29 | Cambodia
30 | Cameroon
31 | Canada
32 | Cape Verde
33 | Central African Rep
34 | Chad
35 | Chile
36 | China
37 | Colombia
38 | Comoros
39 | Congo
40 | Congo {Democratic Rep}
41 | Costa Rica
42 | Croatia
43 | Cuba
44 | Cyprus
45 | Czech Republic
46 | Denmark
47 | Djibouti
48 | Dominica
49 | Dominican Republic
50 | East Timor
51 | Ecuador
52 | Egypt
53 | El Salvador
54 | Equatorial Guinea
55 | Eritrea
56 | Estonia
57 | Ethiopia
58 | Fiji
59 | Finland
60 | France
61 | Gabon
62 | Gambia
63 | Georgia
64 | Germany
65 | Ghana
66 | Greece
67 | Grenada
68 | Guatemala
69 | Guinea
70 | Guinea-Bissau
71 | Guyana
72 | Haiti
73 | Honduras
74 | Hungary
75 | Iceland
76 | India
77 | Indonesia
78 | Iran
79 | Iraq
80 | Ireland {Republic}
81 | Israel
82 | Italy
83 | Ivory Coast
84 | Jamaica
85 | Japan
86 | Jordan
87 | Kazakhstan
88 | Kenya
89 | Kiribati
90 | Korea North
91 | Korea South
92 | Kosovo
93 | Kuwait
94 | Kyrgyzstan
95 | Laos
96 | Latvia
97 | Lebanon
98 | Lesotho
99 | Liberia
100 | Libya
101 | Liechtenstein
102 | Lithuania
103 | Luxembourg
104 | Macedonia
105 | Madagascar
106 | Malawi
107 | Malaysia
108 | Maldives
109 | Mali
110 | Malta
111 | Marshall Islands
112 | Mauritania
113 | Mauritius
114 | Mexico
115 | Micronesia
116 | Moldova
117 | Monaco
118 | Mongolia
119 | Montenegro
120 | Morocco
121 | Mozambique
122 | Myanmar, {Burma}
123 | Namibia
124 | Nauru
125 | Nepal
126 | Netherlands
127 | New Zealand
128 | Nicaragua
129 | Niger
130 | Nigeria
131 | Norway
132 | Oman
133 | Pakistan
134 | Palau
135 | Panama
136 | Papua New Guinea
137 | Paraguay
138 | Peru
139 | Philippines
140 | Poland
141 | Portugal
142 | Qatar
143 | Romania
144 | Russian Federation
145 | Rwanda
146 | St Kitts & Nevis
147 | St Lucia
148 | Saint Vincent & the Grenadines
149 | Samoa
150 | San Marino
151 | Sao Tome & Principe
152 | Saudi Arabia
153 | Senegal
154 | Serbia
155 | Seychelles
156 | Sierra Leone
157 | Singapore
158 | Slovakia
159 | Slovenia
160 | Solomon Islands
161 | Somalia
162 | South Africa
163 | South Sudan
164 | Spain
165 | Sri Lanka
166 | Sudan
167 | Suriname
168 | Swaziland
169 | Sweden
170 | Switzerland
171 | Syria
172 | Taiwan
173 | Tajikistan
174 | Tanzania
175 | Thailand
176 | Togo
177 | Tonga
178 | Trinidad & Tobago
179 | Tunisia
180 | Turkey
181 | Turkmenistan
182 | Tuvalu
183 | Uganda
184 | Ukraine
185 | United Arab Emirates
186 | United Kingdom
187 | United States
188 | Uruguay
189 | Uzbekistan
190 | Vanuatu
191 | Vatican City
192 | Venezuela
193 | Vietnam
194 | Yemen
195 | Zambia
196 | Zimbabwe
197 |
--------------------------------------------------------------------------------
/Problems/Solutions/data/google.html:
--------------------------------------------------------------------------------
1 | Google
--------------------------------------------------------------------------------
/Problems/Solutions/problem_1_review.py:
--------------------------------------------------------------------------------
1 | """
2 | Given a user's input of n, return a list of factorials from 0! to n!
3 |
4 | Test cases:
5 | 0! = 1
6 | 1! = 1
7 | 2! = 1 x 2 = 2
8 | 4! = 1 x 2 x 3 x 4 = 24
9 | """
10 |
11 |
12 | # Helper method to test equality
13 | def assert_equals(actual, expected):
14 | assert actual == expected, f'Expected {expected}, got {actual}'
15 |
16 |
17 | # Create a function that produces the factorial of a number
18 | def factorial(n):
19 | total = 1
20 | for i in range(n):
21 | total *= (i + 1)
22 | return total
23 |
24 |
25 | # Test factorial function
26 | assert_equals(factorial(0), 1)
27 | assert_equals(factorial(1), 1)
28 | assert_equals(factorial(2), 2)
29 | assert_equals(factorial(4), 24)
30 |
31 |
32 | # Request a number from the user
33 | number = int(input("Enter a positive whole number: "))
34 |
35 |
36 | # Print a list of factorials from 0 to the given number
37 | factorials = []
38 | for i in range(number + 1):
39 | factorials.append(factorial(i))
40 |
41 | print(factorials)
42 |
--------------------------------------------------------------------------------
/Problems/Solutions/problem_2_dictionaries.py:
--------------------------------------------------------------------------------
1 | """
2 | Translate a message from the user into a numeric code
3 | """
4 |
5 | code = {
6 | 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9,
7 | 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17,
8 | 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26
9 | }
10 |
11 | # Get a message from the user
12 | message = input("What is your message? ")
13 |
14 | # Translate user input into code of numbers
15 | coded_message = ''
16 | for char in message.lower():
17 | if char in code:
18 | coded_message += str(code[char])
19 | else:
20 | coded_message += char
21 | coded_message += ' '
22 | print(coded_message)
23 |
--------------------------------------------------------------------------------
/Problems/Solutions/problem_3_exceptions.py:
--------------------------------------------------------------------------------
1 | """
2 | Given a temperature (in Celsius), print the state of water at that temperature
3 | """
4 |
5 | while True:
6 | try:
7 | temp = float(input("What's the temperature? "))
8 | break
9 | except ValueError:
10 | print("Try again! It must be a number")
11 |
12 | if temp <= 0:
13 | print(" It’s freezing")
14 | elif temp >= 100:
15 | print(" It’s boiling")
16 | else:
17 | print(" It's alright")
18 |
--------------------------------------------------------------------------------
/Problems/Solutions/problem_4_files.py:
--------------------------------------------------------------------------------
1 | """
2 | A program that takes a letter and outputs a text file of
3 | all of the countries that start with that letter
4 | """
5 |
6 | # Read data/countries.txt and save all countries by starting letter
7 | countries = {}
8 | with open('data/countries.txt', 'r') as file:
9 | for line in file.readlines():
10 | starting_letter = line[0]
11 | country = line.strip()
12 | if starting_letter not in countries:
13 | countries[starting_letter] = []
14 | countries[starting_letter].append(country)
15 |
16 | # Get user to provide a letter
17 | letter = input('Number of countries that start with letter: ').upper()
18 |
19 | # Print the number of countries that start with the letter
20 | letter_countries = countries.get(letter, [])
21 | print(f'{len(letter_countries)} countries start with an {letter}')
22 |
23 | # Create text file that lists the countries starting with the letter
24 | with open(f'data/{letter}_countries.txt', 'w') as file:
25 | for country in letter_countries:
26 | file.write(country + '\n')
27 |
--------------------------------------------------------------------------------
/Problems/Solutions/problem_4b_files_defaultdict.py:
--------------------------------------------------------------------------------
1 | """
2 | A program that takes a letter and outputs a text file of
3 | all of the countries that start with that letter
4 | """
5 | from collections import defaultdict
6 |
7 | countries = defaultdict(list)
8 | with open('data/countries.txt') as file:
9 | for country in file.readlines():
10 | first_letter = country[0].upper()
11 | countries[first_letter].append(country.strip())
12 |
13 |
14 | # Get user to provide a letter
15 | letter = input('Number of countries that start with letter: ')
16 | letter = letter.capitalize()
17 |
18 | letter_countries = countries[letter]
19 |
20 | print(len(letter_countries))
21 | print(letter_countries)
22 |
23 | with open(f'data/{letter}_countries.txt', 'w') as file:
24 | for country in letter_countries:
25 | file.write(country + '\n')
26 |
--------------------------------------------------------------------------------
/Problems/Solutions/problem_5_beautiful_soup.py:
--------------------------------------------------------------------------------
1 | """
2 | Print the text of the two buttons on the Google homepage.
3 |
4 | Documentation: https://www.crummy.com/software/BeautifulSoup/bs4/doc/
5 | """
6 | from bs4 import BeautifulSoup
7 |
8 | with open('data/google.html', 'r') as file:
9 | html_doc = file.read()
10 |
11 | soup = BeautifulSoup(html_doc, 'html.parser')
12 |
13 | buttons = soup.find_all('input', type='submit')
14 | for button in buttons:
15 | print(button['value'])
16 |
--------------------------------------------------------------------------------
/Problems/data/countries.txt:
--------------------------------------------------------------------------------
1 | Afghanistan
2 | Albania
3 | Algeria
4 | Andorra
5 | Angola
6 | Antigua & Deps
7 | Argentina
8 | Armenia
9 | Australia
10 | Austria
11 | Azerbaijan
12 | Bahamas
13 | Bahrain
14 | Bangladesh
15 | Barbados
16 | Belarus
17 | Belgium
18 | Belize
19 | Benin
20 | Bhutan
21 | Bolivia
22 | Bosnia Herzegovina
23 | Botswana
24 | Brazil
25 | Brunei
26 | Bulgaria
27 | Burkina
28 | Burundi
29 | Cambodia
30 | Cameroon
31 | Canada
32 | Cape Verde
33 | Central African Rep
34 | Chad
35 | Chile
36 | China
37 | Colombia
38 | Comoros
39 | Congo
40 | Congo {Democratic Rep}
41 | Costa Rica
42 | Croatia
43 | Cuba
44 | Cyprus
45 | Czech Republic
46 | Denmark
47 | Djibouti
48 | Dominica
49 | Dominican Republic
50 | East Timor
51 | Ecuador
52 | Egypt
53 | El Salvador
54 | Equatorial Guinea
55 | Eritrea
56 | Estonia
57 | Ethiopia
58 | Fiji
59 | Finland
60 | France
61 | Gabon
62 | Gambia
63 | Georgia
64 | Germany
65 | Ghana
66 | Greece
67 | Grenada
68 | Guatemala
69 | Guinea
70 | Guinea-Bissau
71 | Guyana
72 | Haiti
73 | Honduras
74 | Hungary
75 | Iceland
76 | India
77 | Indonesia
78 | Iran
79 | Iraq
80 | Ireland {Republic}
81 | Israel
82 | Italy
83 | Ivory Coast
84 | Jamaica
85 | Japan
86 | Jordan
87 | Kazakhstan
88 | Kenya
89 | Kiribati
90 | Korea North
91 | Korea South
92 | Kosovo
93 | Kuwait
94 | Kyrgyzstan
95 | Laos
96 | Latvia
97 | Lebanon
98 | Lesotho
99 | Liberia
100 | Libya
101 | Liechtenstein
102 | Lithuania
103 | Luxembourg
104 | Macedonia
105 | Madagascar
106 | Malawi
107 | Malaysia
108 | Maldives
109 | Mali
110 | Malta
111 | Marshall Islands
112 | Mauritania
113 | Mauritius
114 | Mexico
115 | Micronesia
116 | Moldova
117 | Monaco
118 | Mongolia
119 | Montenegro
120 | Morocco
121 | Mozambique
122 | Myanmar, {Burma}
123 | Namibia
124 | Nauru
125 | Nepal
126 | Netherlands
127 | New Zealand
128 | Nicaragua
129 | Niger
130 | Nigeria
131 | Norway
132 | Oman
133 | Pakistan
134 | Palau
135 | Panama
136 | Papua New Guinea
137 | Paraguay
138 | Peru
139 | Philippines
140 | Poland
141 | Portugal
142 | Qatar
143 | Romania
144 | Russian Federation
145 | Rwanda
146 | St Kitts & Nevis
147 | St Lucia
148 | Saint Vincent & the Grenadines
149 | Samoa
150 | San Marino
151 | Sao Tome & Principe
152 | Saudi Arabia
153 | Senegal
154 | Serbia
155 | Seychelles
156 | Sierra Leone
157 | Singapore
158 | Slovakia
159 | Slovenia
160 | Solomon Islands
161 | Somalia
162 | South Africa
163 | South Sudan
164 | Spain
165 | Sri Lanka
166 | Sudan
167 | Suriname
168 | Swaziland
169 | Sweden
170 | Switzerland
171 | Syria
172 | Taiwan
173 | Tajikistan
174 | Tanzania
175 | Thailand
176 | Togo
177 | Tonga
178 | Trinidad & Tobago
179 | Tunisia
180 | Turkey
181 | Turkmenistan
182 | Tuvalu
183 | Uganda
184 | Ukraine
185 | United Arab Emirates
186 | United Kingdom
187 | United States
188 | Uruguay
189 | Uzbekistan
190 | Vanuatu
191 | Vatican City
192 | Venezuela
193 | Vietnam
194 | Yemen
195 | Zambia
196 | Zimbabwe
197 |
--------------------------------------------------------------------------------
/Problems/data/google.html:
--------------------------------------------------------------------------------
1 | Google
--------------------------------------------------------------------------------
/Problems/problem_1_review.py:
--------------------------------------------------------------------------------
1 | """
2 | Given a user's input of n, return a list of factorials from 0! to n!
3 |
4 | Test cases:
5 | 0! = 1
6 | 1! = 1
7 | 2! = 1 x 2 = 2
8 | 4! = 1 x 2 x 3 x 4 = 24
9 | """
10 |
11 |
12 | # Helper method to test equality
13 | def assert_equals(actual, expected):
14 | assert actual == expected, f'Expected {expected}, got {actual}'
15 |
16 |
17 | # Todo: Create a function that produces the factorial of a number
18 |
19 |
20 | # Todo: Test factorial function
21 |
22 |
23 | # Todo: Request a number from the user
24 |
25 |
26 | # Todo: Print a list of factorials from 0 to the given number
27 |
28 |
--------------------------------------------------------------------------------
/Problems/problem_2_dictionaries.py:
--------------------------------------------------------------------------------
1 | """
2 | Translate a message from the user into a numeric code
3 | """
4 |
5 | code = {
6 | 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9,
7 | 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17,
8 | 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26
9 | }
10 |
11 | def encrypt(plaintext):
12 | ciphertext = ""
13 | ... # Fill in implementation
14 | return ciphertext
15 |
16 | assert encrypt("hello!") == "8 5 12 12 15 !", f"Got {encrypt('hello')=}"
17 |
18 | # Get a message from the user
19 | message = input("What is your message? ")
20 |
21 | print(encrypt(message))
22 |
--------------------------------------------------------------------------------
/Problems/problem_3_exceptions.py:
--------------------------------------------------------------------------------
1 | """
2 | Given a temperature (in Celsius), print the state of water at that temperature
3 | """
4 |
5 | # Todo: Handle invalid inputs
6 | temp = float(input("What's the H20 temperature? "))
7 |
8 | if temp <= 0:
9 | print(" It’s ice")
10 | elif temp >= 100:
11 | print(" It’s steam")
12 | else:
13 | print(" It's water")
14 |
--------------------------------------------------------------------------------
/Problems/problem_4_files.py:
--------------------------------------------------------------------------------
1 | """
2 | A program that takes a letter and outputs a text file of
3 | all of the countries that start with that letter
4 | """
5 |
6 | # Todo: Read data/countries.txt and save all countries
7 |
8 | # Get user to provide a letter
9 | letter = input('Number of countries that start with letter: ').upper()
10 |
11 | # Todo: Print the number of countries that start with the letter
12 |
13 | # Todo: Create text file that lists the countries starting with the letter
14 |
--------------------------------------------------------------------------------
/Problems/problem_5_beautiful_soup.py:
--------------------------------------------------------------------------------
1 | """
2 | Print the text of the two buttons on the Google homepage.
3 |
4 | Documentation: https://www.crummy.com/software/BeautifulSoup/bs4/doc/
5 | """
6 | from bs4 import BeautifulSoup
7 |
8 | with open('data/google.html', 'r') as file:
9 | html_doc = file.read()
10 |
11 | print(html_doc)
12 |
--------------------------------------------------------------------------------
/Project/Solutions/a_print_to_txt/countries.txt:
--------------------------------------------------------------------------------
1 | Afghanistan
2 | Albania
3 | Algeria
4 | Andorra
5 | Angola
6 | Antigua and Barbuda
7 | Argentina
8 | Armenia
9 | Australia
10 | Austria
11 | Azerbaijan
12 | Bahamas
13 | Bahrain
14 | Bangladesh
15 | Barbados
16 | Belarus
17 | Belgium
18 | Belize
19 | Benin
20 | Bhutan
21 | Plurinational State of Bolivia
22 | Bosnia and Herzegovina
23 | Botswana
24 | Brazil
25 | Brunei Darussalam
26 | Bulgaria
27 | Burkina Faso
28 | Burundi
29 | Cabo Verde
30 | Cambodia
31 | Cameroon
32 | Canada
33 | Central African Republic
34 | Chad
35 | Chile
36 | China
37 | Colombia
38 | Comoros
39 | Congo
40 | Costa Rica
41 | Côte d'Ivoire
42 | Croatia
43 | Cuba
44 | Cyprus
45 | Czechia
46 | Democratic People's Republic of Korea
47 | Democratic Republic of the Congo
48 | Denmark
49 | Djibouti
50 | Dominica
51 | Dominican Republic
52 | Ecuador
53 | Egypt
54 | El Salvador
55 | Equatorial Guinea
56 | Eritrea
57 | Estonia
58 | Eswatini
59 | Ethiopia
60 | Fiji
61 | Finland
62 | France
63 | Gabon
64 | Gambia
65 | Georgia
66 | Germany
67 | Ghana
68 | Greece
69 | Grenada
70 | Guatemala
71 | Guinea
72 | Guinea Bissau
73 | Guyana
74 | Haiti
75 | Honduras
76 | Hungary
77 | Iceland
78 | India
79 | Indonesia
80 | Iran
81 | Iraq
82 | Ireland
83 | Israel
84 | Italy
85 | Jamaica
86 | Japan
87 | Jordan
88 | Kazakhstan
89 | Kenya
90 | Kiribati
91 | Kuwait
92 | Kyrgyzstan
93 | Lao People's Democratic Republic
94 | Latvia
95 | Lebanon
96 | Lesotho
97 | Liberia
98 | Libya
99 | Liechtenstein
100 | Lithuania
101 | Luxembourg
102 | Madagascar
103 | Malawi
104 | Malaysia
105 | Maldives
106 | Mali
107 | Malta
108 | Marshall Islands
109 | Mauritania
110 | Mauritius
111 | Mexico
112 | Micronesia
113 | Monaco
114 | Mongolia
115 | Montenegro
116 | Morocco
117 | Mozambique
118 | Myanmar
119 | Namibia
120 | Nauru
121 | Nepal
122 | Netherlands
123 | New Zealand
124 | Nicaragua
125 | Niger
126 | Nigeria
127 | North Macedonia
128 | Norway
129 | Oman
130 | Pakistan
131 | Palau
132 | Panama
133 | Papua New Guinea
134 | Paraguay
135 | Peru
136 | Philippines
137 | Poland
138 | Portugal
139 | Qatar
140 | Republic of Korea
141 | Republic of Moldova
142 | Romania
143 | Russian Federation
144 | Rwanda
145 | Saint Kitts and Nevis
146 | Saint Lucia
147 | Saint Vincent and the Grenadines
148 | Samoa
149 | San Marino
150 | Sao Tome and Principe
151 | Saudi Arabia
152 | Senegal
153 | Serbia
154 | Seychelles
155 | Sierra Leone
156 | Singapore
157 | Slovakia
158 | Slovenia
159 | Solomon Islands
160 | Somalia
161 | South Africa
162 | South Sudan
163 | Spain
164 | Sri Lanka
165 | Sudan
166 | Suriname
167 | Sweden
168 | Switzerland
169 | Syrian Arab Republic
170 | Tajikistan
171 | Thailand
172 | Timor-Leste
173 | Togo
174 | Tonga
175 | Trinidad and Tobago
176 | Tunisia
177 | Türkiye
178 | Turkmenistan
179 | Tuvalu
180 | Uganda
181 | Ukraine
182 | United Arab Emirates
183 | United Kingdom of Great Britain and Northern Ireland
184 | United Republic of Tanzania
185 | United States of America
186 | Uruguay
187 | Uzbekistan
188 | Vanuatu
189 | Venezuela
190 | Viet Nam
191 | Yemen
192 | Zambia
193 | Zimbabwe
--------------------------------------------------------------------------------
/Project/Solutions/a_print_to_txt/scraper.py:
--------------------------------------------------------------------------------
1 | import requests
2 | from bs4 import BeautifulSoup
3 |
4 | URL = "https://en.wikipedia.org/wiki/Member_states_of_the_United_Nations"
5 |
6 | response = requests.get(URL)
7 | response.raise_for_status()
8 | html_doc = response.text
9 |
10 | soup = BeautifulSoup(html_doc, 'html.parser')
11 |
12 | table = soup.find('table', class_='wikitable')
13 | rows = table.find_all('tr')
14 |
15 | countries = []
16 |
17 | for row in rows:
18 | name_link = row.th.a
19 | if not name_link:
20 | continue
21 |
22 | name: str = name_link.string
23 | countries.append(name.split(' (')[0])
24 |
25 | with open('countries.txt', 'w') as file:
26 | file.write('\n'.join(countries))
--------------------------------------------------------------------------------
/Project/Solutions/b_print_to_csv/countries.csv:
--------------------------------------------------------------------------------
1 | Name,Date joined
2 | Afghanistan,19 November 1946
3 | Albania,14 December 1955
4 | Algeria,8 October 1962
5 | Andorra,28 July 1993
6 | Angola,1 December 1976
7 | Antigua and Barbuda,11 November 1981
8 | Argentina,24 October 1945
9 | Armenia,2 March 1992
10 | Australia,1 November 1945
11 | Austria,14 December 1955
12 | Azerbaijan,2 March 1992
13 | Bahamas,18 September 1973
14 | Bahrain,21 September 1971
15 | Bangladesh,17 September 1974
16 | Barbados,9 December 1966
17 | Belarus,24 October 1945
18 | Belgium,27 December 1945
19 | Belize,25 September 1981
20 | Benin,20 September 1960
21 | Bhutan,21 September 1971
22 | Bolivia,14 November 1945
23 | Bosnia and Herzegovina,22 May 1992
24 | Botswana,17 October 1966
25 | Brazil,24 October 1945
26 | Brunei Darussalam,21 September 1984
27 | Bulgaria,14 December 1955
28 | Burkina Faso,20 September 1960
29 | Burundi,18 September 1962
30 | Cabo Verde,16 September 1975
31 | Cambodia,14 December 1955
32 | Cameroon,20 September 1960
33 | Canada,9 November 1945
34 | Central African Republic,20 September 1960
35 | Chad,20 September 1960
36 | Chile,24 October 1945
37 | China,24 October 1945
38 | Colombia,5 November 1945
39 | Comoros,12 November 1975
40 | Congo,20 September 1960
41 | Costa Rica,2 November 1945
42 | Côte d'Ivoire,20 September 1960
43 | Croatia,22 May 1992
44 | Cuba,24 October 1945
45 | Cyprus,20 September 1960
46 | Czechia,19 January 1993
47 | Democratic People's Republic of Korea,17 September 1991
48 | Democratic Republic of the Congo,20 September 1960
49 | Denmark,24 October 1945
50 | Djibouti,20 September 1977
51 | Dominica,18 December 1978
52 | Dominican Republic,24 October 1945
53 | Ecuador,21 December 1945
54 | Egypt,24 October 1945
55 | El Salvador,24 October 1945
56 | Equatorial Guinea,12 November 1968
57 | Eritrea,28 May 1993
58 | Estonia,17 September 1991
59 | Eswatini,24 September 1968
60 | Ethiopia,13 November 1945
61 | Fiji,13 October 1970
62 | Finland,14 December 1955
63 | France,24 October 1945
64 | Gabon,20 September 1960
65 | Gambia,21 September 1965
66 | Georgia,31 July 1992
67 | Germany,18 September 1973
68 | Ghana,8 March 1957
69 | Greece,25 October 1945
70 | Grenada,17 September 1974
71 | Guatemala,21 November 1945
72 | Guinea,12 December 1958
73 | Guinea Bissau,17 September 1974
74 | Guyana,20 September 1966
75 | Haiti,24 October 1945
76 | Honduras,17 December 1945
77 | Hungary,14 December 1955
78 | Iceland,19 November 1946
79 | India,30 October 1945
80 | Indonesia,28 September 1950
81 | Iran,24 October 1945
82 | Iraq,21 December 1945
83 | Ireland,14 December 1955
84 | Israel,11 May 1949
85 | Italy,14 December 1955
86 | Jamaica,18 September 1962
87 | Japan,18 December 1956
88 | Jordan,14 December 1955
89 | Kazakhstan,2 March 1992
90 | Kenya,16 December 1963
91 | Kiribati,14 September 1999
92 | Kuwait,14 May 1963
93 | Kyrgyzstan,2 March 1992
94 | Lao People's Democratic Republic,14 December 1955
95 | Latvia,17 September 1991
96 | Lebanon,24 October 1945
97 | Lesotho,17 October 1966
98 | Liberia,2 November 1945
99 | Libya,14 December 1955
100 | Liechtenstein,18 September 1990
101 | Lithuania,17 September 1991
102 | Luxembourg,24 October 1945
103 | Madagascar,20 September 1960
104 | Malawi,1 December 1964
105 | Malaysia,17 September 1957
106 | Maldives,21 September 1965
107 | Mali,28 September 1960
108 | Malta,1 December 1964
109 | Marshall Islands,17 September 1991
110 | Mauritania,27 October 1961
111 | Mauritius,24 April 1968
112 | Mexico,7 November 1945
113 | Micronesia,17 September 1991
114 | Monaco,28 May 1993
115 | Mongolia,27 October 1961
116 | Montenegro,28 June 2006
117 | Morocco,12 November 1956
118 | Mozambique,16 September 1975
119 | Myanmar,19 April 1948
120 | Namibia,23 April 1990
121 | Nauru,14 September 1999
122 | Nepal,14 December 1955
123 | Netherlands,10 December 1945
124 | New Zealand,24 October 1945
125 | Nicaragua,24 October 1945
126 | Niger,20 September 1960
127 | Nigeria,7 October 1960
128 | North Macedonia,8 April 1993
129 | Norway,27 November 1945
130 | Oman,7 October 1971
131 | Pakistan,30 September 1947
132 | Palau,15 December 1994
133 | Panama,13 November 1945
134 | Papua New Guinea,10 October 1975
135 | Paraguay,24 October 1945
136 | Peru,31 October 1945
137 | Philippines,24 October 1945
138 | Poland,24 October 1945
139 | Portugal,14 December 1955
140 | Qatar,21 September 1971
141 | Republic of Korea,17 September 1991
142 | Republic of Moldova,2 March 1992
143 | Romania,14 December 1955
144 | Russian Federation,24 October 1945
145 | Rwanda,18 September 1962
146 | Saint Kitts and Nevis,23 September 1983
147 | Saint Lucia,18 September 1979
148 | Saint Vincent and the Grenadines,16 September 1980
149 | Samoa,15 December 1976
150 | San Marino,2 March 1992
151 | Sao Tome and Principe,16 September 1975
152 | Saudi Arabia,24 October 1945
153 | Senegal,28 September 1960
154 | Serbia,1 November 2000
155 | Seychelles,21 September 1976
156 | Sierra Leone,27 September 1961
157 | Singapore,21 September 1965
158 | Slovakia,19 January 1993
159 | Slovenia,22 May 1992
160 | Solomon Islands,19 September 1978
161 | Somalia,20 September 1960
162 | South Africa,7 November 1945
163 | South Sudan,14 July 2011
164 | Spain,14 December 1955
165 | Sri Lanka,14 December 1955
166 | Sudan,12 November 1956
167 | Suriname,4 December 1975
168 | Sweden,19 November 1946
169 | Switzerland,10 September 2002
170 | Syrian Arab Republic,24 October 1945
171 | Tajikistan,2 March 1992
172 | Thailand,16 December 1946
173 | Timor-Leste,27 September 2002
174 | Togo,20 September 1960
175 | Tonga,14 September 1999
176 | Trinidad and Tobago,18 September 1962
177 | Tunisia,12 November 1956
178 | Türkiye,24 October 1945
179 | Turkmenistan,2 March 1992
180 | Tuvalu,5 September 2000
181 | Uganda,25 October 1962
182 | Ukraine,24 October 1945
183 | United Arab Emirates,9 December 1971
184 | United Kingdom of Great Britain and Northern Ireland,24 October 1945
185 | United Republic of Tanzania,14 December 1961
186 | United States of America,24 October 1945
187 | Uruguay,18 December 1945
188 | Uzbekistan,2 March 1992
189 | Vanuatu,15 September 1981
190 | Bolivarian Republic of Venezuela,15 November 1945
191 | Viet Nam,20 September 1977
192 | Yemen,30 September 1947
193 | Zambia,1 December 1964
194 | Zimbabwe,25 August 1980
195 |
--------------------------------------------------------------------------------
/Project/Solutions/b_print_to_csv/scraper.py:
--------------------------------------------------------------------------------
1 | import csv
2 |
3 | import requests
4 | from bs4 import BeautifulSoup
5 |
6 | URL = 'https://en.wikipedia.org/wiki/Member_states_of_the_United_Nations'
7 |
8 | response = requests.get(URL)
9 | response.raise_for_status()
10 |
11 | html_doc = response.text
12 |
13 | soup = BeautifulSoup(html_doc, 'html.parser')
14 |
15 | table = soup.find('table', class_='wikitable')
16 |
17 | countries = []
18 |
19 | for row in table.find_all('tr'):
20 | a = row.th.a
21 | if a is None:
22 | continue
23 |
24 | link_content: str = a.string
25 | name = link_content.split(' (')[0]
26 | date_joined = row.td.span.string
27 |
28 | country = {
29 | 'Name': name,
30 | 'Date joined': date_joined,
31 | }
32 | countries.append(country)
33 |
34 | print(countries)
35 |
36 | with open('countries.csv', 'w') as file:
37 | writer = csv.DictWriter(file, ['Name', 'Date joined'])
38 | writer.writeheader()
39 | writer.writerows(countries)
40 |
--------------------------------------------------------------------------------
/Project/Solutions/c_more_data/countries_more.csv:
--------------------------------------------------------------------------------
1 | Name,Date joined,Latitude,Longitude,URL
2 | Afghanistan,19 November 1946,34°31′N,69°11′E,/wiki/Afghanistan
3 | Albania,14 December 1955,41°N,20°E,/wiki/Albania
4 | Algeria,8 October 1962,28°N,2°E,/wiki/Algeria
5 | Andorra,28 July 1993,,,/wiki/Andorra
6 | Angola,1 December 1976,,,/wiki/Angola
7 | Antigua and Barbuda,11 November 1981,,,/wiki/Antigua_and_Barbuda
8 | Argentina,24 October 1945,,,/wiki/Argentina
9 | Armenia,2 March 1992,,,/wiki/Armenia
10 | Australia,1 November 1945,,,/wiki/Australia
11 | Austria,14 December 1955,,,/wiki/Austria
12 | Azerbaijan,2 March 1992,,,/wiki/Azerbaijan
13 | Bahamas,18 September 1973,,,/wiki/The_Bahamas
14 | Bahrain,21 September 1971,,,/wiki/Bahrain
15 | Bangladesh,17 September 1974,,,/wiki/Bangladesh
16 | Barbados,9 December 1966,,,/wiki/Barbados
17 | Belarus,24 October 1945,,,/wiki/Belarus
18 | Belgium,27 December 1945,,,/wiki/Belgium
19 | Belize,25 September 1981,,,/wiki/Belize
20 | Benin,20 September 1960,,,/wiki/Benin
21 | Bhutan,21 September 1971,,,/wiki/Bhutan
22 | Bolivia,14 November 1945,,,/wiki/Bolivia
23 | Bosnia and Herzegovina,22 May 1992,,,/wiki/Bosnia_and_Herzegovina
24 | Botswana,17 October 1966,,,/wiki/Botswana
25 | Brazil,24 October 1945,,,/wiki/Brazil
26 | Brunei Darussalam,21 September 1984,,,/wiki/Brunei
27 | Bulgaria,14 December 1955,,,/wiki/Bulgaria
28 | Burkina Faso,20 September 1960,,,/wiki/Burkina_Faso
29 | Burundi,18 September 1962,,,/wiki/Burundi
30 | Cabo Verde,16 September 1975,,,/wiki/Cape_Verde
31 | Cambodia,14 December 1955,,,/wiki/Cambodia
32 | Cameroon,20 September 1960,,,/wiki/Cameroon
33 | Canada,9 November 1945,,,/wiki/Canada
34 | Central African Republic,20 September 1960,,,/wiki/Central_African_Republic
35 | Chad,20 September 1960,,,/wiki/Chad
36 | Chile,24 October 1945,,,/wiki/Chile
37 | China,24 October 1945,,,/wiki/China
38 | Colombia,5 November 1945,,,/wiki/Colombia
39 | Comoros,12 November 1975,,,/wiki/Comoros
40 | Congo,20 September 1960,,,/wiki/Republic_of_the_Congo
41 | Costa Rica,2 November 1945,,,/wiki/Costa_Rica
42 | Côte d'Ivoire,20 September 1960,,,/wiki/Ivory_Coast
43 | Croatia,22 May 1992,,,/wiki/Croatia
44 | Cuba,24 October 1945,,,/wiki/Cuba
45 | Cyprus,20 September 1960,,,/wiki/Cyprus
46 | Czechia,19 January 1993,,,/wiki/Czech_Republic
47 | Democratic People's Republic of Korea,17 September 1991,,,/wiki/Democratic_People%27s_Republic_of_Korea
48 | Democratic Republic of the Congo,20 September 1960,,,/wiki/Democratic_Republic_of_the_Congo
49 | Denmark,24 October 1945,,,/wiki/Danish_Realm
50 | Djibouti,20 September 1977,,,/wiki/Djibouti
51 | Dominica,18 December 1978,,,/wiki/Dominica
52 | Dominican Republic,24 October 1945,,,/wiki/Dominican_Republic
53 | Ecuador,21 December 1945,,,/wiki/Ecuador
54 | Egypt,24 October 1945,,,/wiki/Egypt
55 | El Salvador,24 October 1945,,,/wiki/El_Salvador
56 | Equatorial Guinea,12 November 1968,,,/wiki/Equatorial_Guinea
57 | Eritrea,28 May 1993,,,/wiki/Eritrea
58 | Estonia,17 September 1991,,,/wiki/Estonia
59 | Eswatini,24 September 1968,,,/wiki/Eswatini
60 | Ethiopia,13 November 1945,,,/wiki/Ethiopia
61 | Fiji,13 October 1970,,,/wiki/Fiji
62 | Finland,14 December 1955,,,/wiki/Finland
63 | France,24 October 1945,,,/wiki/France
64 | Gabon,20 September 1960,,,/wiki/Gabon
65 | Gambia,21 September 1965,,,/wiki/The_Gambia
66 | Georgia,31 July 1992,,,/wiki/Georgia_(country)
67 | Germany,18 September 1973,,,/wiki/Germany
68 | Ghana,8 March 1957,,,/wiki/Ghana
69 | Greece,25 October 1945,,,/wiki/Greece
70 | Grenada,17 September 1974,,,/wiki/Grenada
71 | Guatemala,21 November 1945,,,/wiki/Guatemala
72 | Guinea,12 December 1958,,,/wiki/Guinea
73 | Guinea Bissau,17 September 1974,,,/wiki/Guinea-Bissau
74 | Guyana,20 September 1966,,,/wiki/Guyana
75 | Haiti,24 October 1945,,,/wiki/Haiti
76 | Honduras,17 December 1945,,,/wiki/Honduras
77 | Hungary,14 December 1955,,,/wiki/Hungary
78 | Iceland,19 November 1946,,,/wiki/Iceland
79 | India,30 October 1945,,,/wiki/India
80 | Indonesia,28 September 1950,,,/wiki/Indonesia
81 | Iran,24 October 1945,,,/wiki/Iran
82 | Iraq,21 December 1945,,,/wiki/Iraq
83 | Ireland,14 December 1955,,,/wiki/Republic_of_Ireland
84 | Israel,11 May 1949,,,/wiki/Israel
85 | Italy,14 December 1955,,,/wiki/Italy
86 | Jamaica,18 September 1962,,,/wiki/Jamaica
87 | Japan,18 December 1956,,,/wiki/Japan
88 | Jordan,14 December 1955,,,/wiki/Jordan
89 | Kazakhstan,2 March 1992,,,/wiki/Kazakhstan
90 | Kenya,16 December 1963,,,/wiki/Kenya
91 | Kiribati,14 September 1999,,,/wiki/Kiribati
92 | Kuwait,14 May 1963,,,/wiki/Kuwait
93 | Kyrgyzstan,2 March 1992,,,/wiki/Kyrgyzstan
94 | Lao People's Democratic Republic,14 December 1955,,,/wiki/Laos
95 | Latvia,17 September 1991,,,/wiki/Latvia
96 | Lebanon,24 October 1945,,,/wiki/Lebanon
97 | Lesotho,17 October 1966,,,/wiki/Lesotho
98 | Liberia,2 November 1945,,,/wiki/Liberia
99 | Libya,14 December 1955,,,/wiki/Libya
100 | Liechtenstein,18 September 1990,,,/wiki/Liechtenstein
101 | Lithuania,17 September 1991,,,/wiki/Lithuania
102 | Luxembourg,24 October 1945,,,/wiki/Luxembourg
103 | Madagascar,20 September 1960,,,/wiki/Madagascar
104 | Malawi,1 December 1964,,,/wiki/Malawi
105 | Malaysia,17 September 1957,,,/wiki/Malaysia
106 | Maldives,21 September 1965,,,/wiki/Maldives
107 | Mali,28 September 1960,,,/wiki/Mali
108 | Malta,1 December 1964,,,/wiki/Malta
109 | Marshall Islands,17 September 1991,,,/wiki/Marshall_Islands
110 | Mauritania,27 October 1961,,,/wiki/Mauritania
111 | Mauritius,24 April 1968,,,/wiki/Mauritius
112 | Mexico,7 November 1945,,,/wiki/Mexico
113 | Micronesia,17 September 1991,,,/wiki/Federated_States_of_Micronesia
114 | Monaco,28 May 1993,,,/wiki/Monaco
115 | Mongolia,27 October 1961,,,/wiki/Mongolia
116 | Montenegro,28 June 2006,,,/wiki/Montenegro
117 | Morocco,12 November 1956,,,/wiki/Morocco
118 | Mozambique,16 September 1975,,,/wiki/Mozambique
119 | Myanmar,19 April 1948,,,/wiki/Myanmar
120 | Namibia,23 April 1990,,,/wiki/Namibia
121 | Nauru,14 September 1999,,,/wiki/Nauru
122 | Nepal,14 December 1955,,,/wiki/Nepal
123 | Netherlands,10 December 1945,,,/wiki/Netherlands
124 | New Zealand,24 October 1945,,,/wiki/New_Zealand
125 | Nicaragua,24 October 1945,,,/wiki/Nicaragua
126 | Niger,20 September 1960,,,/wiki/Niger
127 | Nigeria,7 October 1960,,,/wiki/Nigeria
128 | North Macedonia,8 April 1993,,,/wiki/North_Macedonia
129 | Norway,27 November 1945,,,/wiki/Norway
130 | Oman,7 October 1971,,,/wiki/Oman
131 | Pakistan,30 September 1947,,,/wiki/Pakistan
132 | Palau,15 December 1994,,,/wiki/Palau
133 | Panama,13 November 1945,,,/wiki/Panama
134 | Papua New Guinea,10 October 1975,,,/wiki/Papua_New_Guinea
135 | Paraguay,24 October 1945,,,/wiki/Paraguay
136 | Peru,31 October 1945,,,/wiki/Peru
137 | Philippines,24 October 1945,,,/wiki/Philippines
138 | Poland,24 October 1945,,,/wiki/Poland
139 | Portugal,14 December 1955,,,/wiki/Portugal
140 | Qatar,21 September 1971,,,/wiki/Qatar
141 | Republic of Korea,17 September 1991,,,/wiki/Republic_of_Korea
142 | Republic of Moldova,2 March 1992,,,/wiki/Moldova
143 | Romania,14 December 1955,,,/wiki/Romania
144 | Russian Federation,24 October 1945,,,/wiki/Russia
145 | Rwanda,18 September 1962,,,/wiki/Rwanda
146 | Saint Kitts and Nevis,23 September 1983,,,/wiki/Saint_Kitts_and_Nevis
147 | Saint Lucia,18 September 1979,,,/wiki/Saint_Lucia
148 | Saint Vincent and the Grenadines,16 September 1980,,,/wiki/Saint_Vincent_and_the_Grenadines
149 | Samoa,15 December 1976,,,/wiki/Samoa
150 | San Marino,2 March 1992,,,/wiki/San_Marino
151 | Sao Tome and Principe,16 September 1975,,,/wiki/S%C3%A3o_Tom%C3%A9_and_Pr%C3%ADncipe
152 | Saudi Arabia,24 October 1945,,,/wiki/Saudi_Arabia
153 | Senegal,28 September 1960,,,/wiki/Senegal
154 | Serbia,1 November 2000,,,/wiki/Serbia
155 | Seychelles,21 September 1976,,,/wiki/Seychelles
156 | Sierra Leone,27 September 1961,,,/wiki/Sierra_Leone
157 | Singapore,21 September 1965,,,/wiki/Singapore
158 | Slovakia,19 January 1993,,,/wiki/Slovakia
159 | Slovenia,22 May 1992,,,/wiki/Slovenia
160 | Solomon Islands,19 September 1978,,,/wiki/Solomon_Islands
161 | Somalia,20 September 1960,,,/wiki/Somalia
162 | South Africa,7 November 1945,,,/wiki/South_Africa
163 | South Sudan,14 July 2011,,,/wiki/South_Sudan
164 | Spain,14 December 1955,,,/wiki/Spain
165 | Sri Lanka,14 December 1955,,,/wiki/Sri_Lanka
166 | Sudan,12 November 1956,,,/wiki/Sudan
167 | Suriname,4 December 1975,,,/wiki/Suriname
168 | Sweden,19 November 1946,,,/wiki/Sweden
169 | Switzerland,10 September 2002,,,/wiki/Switzerland
170 | Syrian Arab Republic,24 October 1945,,,/wiki/Syria
171 | Tajikistan,2 March 1992,,,/wiki/Tajikistan
172 | Thailand,16 December 1946,,,/wiki/Thailand
173 | Timor-Leste,27 September 2002,,,/wiki/Timor-Leste
174 | Togo,20 September 1960,,,/wiki/Togo
175 | Tonga,14 September 1999,,,/wiki/Tonga
176 | Trinidad and Tobago,18 September 1962,,,/wiki/Trinidad_and_Tobago
177 | Tunisia,12 November 1956,,,/wiki/Tunisia
178 | Türkiye,24 October 1945,,,/wiki/Turkey
179 | Turkmenistan,2 March 1992,,,/wiki/Turkmenistan
180 | Tuvalu,5 September 2000,,,/wiki/Tuvalu
181 | Uganda,25 October 1962,,,/wiki/Uganda
182 | Ukraine,24 October 1945,,,/wiki/Ukraine
183 | United Arab Emirates,9 December 1971,,,/wiki/United_Arab_Emirates
184 | United Kingdom of Great Britain and Northern Ireland,24 October 1945,,,/wiki/United_Kingdom
185 | United Republic of Tanzania,14 December 1961,,,/wiki/Tanzania
186 | United States of America,24 October 1945,,,/wiki/United_States
187 | Uruguay,18 December 1945,,,/wiki/Uruguay
188 | Uzbekistan,2 March 1992,,,/wiki/Uzbekistan
189 | Vanuatu,15 September 1981,,,/wiki/Vanuatu
190 | Bolivarian Republic of Venezuela,15 November 1945,,,/wiki/Venezuela
191 | Viet Nam,20 September 1977,,,/wiki/Vietnam
192 | Yemen,30 September 1947,,,/wiki/Yemen
193 | Zambia,1 December 1964,,,/wiki/Zambia
194 | Zimbabwe,25 August 1980,,,/wiki/Zimbabwe
195 |
--------------------------------------------------------------------------------
/Project/Solutions/c_more_data/scraper.py:
--------------------------------------------------------------------------------
1 | import csv
2 | import time
3 |
4 | import requests
5 | from bs4 import BeautifulSoup
6 |
7 | BASE_URL = 'https://en.wikipedia.org'
8 | URL = BASE_URL + '/wiki/Member_states_of_the_United_Nations'
9 |
10 | response = requests.get(URL)
11 | response.raise_for_status()
12 |
13 | html_doc = response.text
14 |
15 | soup = BeautifulSoup(html_doc, 'html.parser')
16 |
17 | table = soup.find('table', class_='wikitable')
18 |
19 | countries = []
20 |
21 | for row in table.find_all('tr'):
22 | link = row.th.a
23 | if link is None:
24 | continue
25 |
26 | href = link['href']
27 | link_content: str = link.string
28 | name = link_content.split(' (')[0]
29 | date_joined = row.td.span.string
30 |
31 | country = {
32 | 'Name': name,
33 | 'Date joined': date_joined,
34 | 'URL': href,
35 | }
36 | countries.append(country)
37 |
38 | for country in countries[:3]:
39 | response = requests.get(BASE_URL + country['URL'])
40 | html_doc = response.text
41 | soup = BeautifulSoup(html_doc, 'html.parser')
42 |
43 | country['Latitude'] = soup.find('span', class_='latitude').string
44 | country['Longitude'] = soup.find('span', class_='longitude').string
45 | time.sleep(0.5)
46 |
47 | print(countries)
48 |
49 | with open('countries.csv', 'w') as file:
50 | writer = csv.DictWriter(file, ['Name', 'Date joined', 'Latitude', 'Longitude', 'URL'])
51 | writer.writeheader()
52 | writer.writerows(countries)
53 |
--------------------------------------------------------------------------------
/Project/scraper.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ariannedee/python-level-2/ed532c42bb2825529a438f8675dc16f2ca6eb756/Project/scraper.py
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Programming with Python: Beyond the Basics Live Training
2 | _How to Write a Web Scraper in Python_
3 |
4 | This is the code for the *O'Reilly Live Training* - **Programming with Python: Beyond the Basics** presented by Arianne Dee
5 |
6 | Before the class, please follow these instructions:
7 | 1. [Install Python](#1-install-python-38-or-higher)
8 | 2. [Choose an IDE](#2-choose-an-ide)
9 | 3. [Download the code](#3-download-the-course-files)
10 | 4. [Setup before class](#4-setup-before-class)
11 | 5. [At the start of class](#5-at-the-start-of-class)
12 |
13 | ## Set up instructions
14 | ### 1. Install Python 3.8 or higher
15 | Go to https://www.python.org/downloads/
16 |
17 | Click the yellow button at the top to download the latest version of Python.
18 |
19 | #### On Mac or Linux
20 | Follow the prompts and install using the default settings.
21 |
22 | #### On Windows
23 | The default settings don't add Python to your PATH
24 | so your computer doesn't know where to look for it when Python runs
25 | (for some inexplicable reason).
26 |
27 | ##### If you're just installing Python now
28 | Follow the instructions here: [Windows Python installer instructions](docs/WININSTALL.md)
29 |
30 | ##### If you've already installed Python with the default settings
31 | Follow the instructions here: [Add Python to PATH variable in Windows](docs/WINSETPATH.md)
32 |
33 | #### Make sure that Python is properly installed
34 | 1. Open the *Command Prompt* application in Windows
35 | or *Terminal* on Mac or Linux
36 |
37 | 1. Type `python --version` and press enter
38 |
39 | 1. Type `python3 --version` and press enter
40 |
41 | 1. Type `py --version` and press enter
42 |
43 | 1. One of those commands should print
44 | a Python version of 3.6 or higher
45 | (whichever version you just downloaded).
46 | If it doesn't, you have to follow instructions to
47 | [add Python to your PATH variable](docs/WINSETPATH.md).
48 |
49 | **Note:**
50 | You can now type just the `python`, `python3`, or `py` command
51 | in *Command Prompt* or *Terminal*
52 | to run the Python interpreter.
53 | You can also run a *.py* file by running
54 | `python filename.py`
55 |
56 | ### 2. Choose an IDE
57 | An IDE is the program that you write code in.
58 | In this class, I will be using PyCharm (Community Edition).
59 | I highly recommend it for writing Python code,
60 | but you are free to follow along in your IDE of choice.
61 |
62 | Download here: https://www.jetbrains.com/pycharm/download/
63 |
64 | Install, open, and use the default settings.
65 |
66 | ### 3. Download the course files
67 | If you're viewing this on GitHub already, stay on this page.
68 | Otherwise, go to the GitHub repository: https://github.com/ariannedee/python-level-2
69 |
70 | #### If you know git:
71 | Clone the repository.
72 |
73 | #### If you don't know git:
74 | 1. Click the "Code" (green) button at the top-right of the page
75 | 2. Click "Download ZIP"
76 | 3. Unzip it and move the **python-level-2-main** folder to a convenient location
77 |
78 | ### 4. Setup before class
79 | Open your IDE and load the course files.
80 | Run the file `python-level-2-master/Examples/example_1_review.py` and make sure it runs properly.
81 |
82 | If you get an error running that file, follow the instructions here to configure your Python version in PyCharm:
83 | [Python interpreter setup](docs/PyCharm_interpreter.md)
84 |
85 | ### 5. At the start of class
86 | Download the PDF of the slides and reference material.
87 | These should be in the **Resources** widget
88 |
89 | ## FAQs
90 | ### Can I use Python 2?
91 |
92 | Yes, but I highly recommend using Python 3.
93 | If you are using Python 2, a few commands will be different and you can't use [f-strings](https://realpython.com/python-f-strings/) to format strings.
94 | Please see the accompanying resource PDF (page 5) for a list of differences you'll see in this class.
95 |
96 | ### Can I use a different code editor besides PyCharm?
97 |
98 | Yes, but it is only recommended if you are already know it and are comfortable navigating to different files and running commands in the command line.
99 | If it has syntax highlighting for Python, that is ideal.
100 |
101 | ### PyCharm can't find Python 3
102 |
103 | Visual instructions here: [Python interpreter setup](docs/PyCharm_interpreter.md)
104 |
105 | On a Mac:
106 | - Go to **PyCharm** > **Preferences**
107 |
108 | On a PC:
109 | - Go to **File** > **Settings**
110 |
111 | Once in Settings:
112 | 1. Go to **Project: python-level-2** > **Project Interpreter**
113 | 1. Look for your Python version in the Project Interpreter dropdown
114 | 1. If it's not there, click **gear icon** > **Add...**
115 | 1. In the new window, select **System Interpreter** on the left, and then look for the Python version in the dropdown
116 | 1. If it's not there, click the **...** button and navigate to your Python location
117 | - To find where Python is located, [look in these directories](docs/PATH_LOCATIONS.md)
118 | - You may have to search the internet for where Python gets installed by default on your operating system
119 |
120 | ### Do you offer private Python help?
121 | Yes, email **arianne.dee.studios at gmail.com** if you have any questions
122 | or would like to set up some remote training.
123 |
--------------------------------------------------------------------------------
/docs/PATH_LOCATIONS.md:
--------------------------------------------------------------------------------
1 | # Locating Python on your computer
2 | If you are trying to find the location of Python3 on your computer,
3 | try these locations first.
4 | The exact location and filename will depend
5 | on the method you used to install Python
6 | and which version is installed.
7 |
8 | ## Windows
9 | Look for `python.exe`
10 | - C:\Python39
11 | - C:\Program Files\Python39
12 | - C:\Users\\*username*\AppData\Local\Programs\Python\Python39-XX
13 |
14 | ## Mac
15 | Look for `python3.9` or `python3`
16 |
17 | - /usr/local/bin
18 | - /Library/Frameworks/Python.framework/Versions/3.9/bin/
19 | - /usr/local/Cellar/python/3.9.X_X/bin/
20 | - /Users/*username*/anaconda/bin/
21 | - /anaconda3/bin/
22 |
23 | ## Linux
24 | Look for `python3.9` or `python3`
25 | - /usr/bin/
26 | - /usr/local/bin
27 |
28 | ### Finally
29 | If you didn't find it at any of these locations,
30 | try searching google more specifically based on
31 | your Python version, operating system, and method of download.
32 |
33 | If you found it at another location, please email me at
34 | **arianne.dee.studios@gmail.com** so I can update this list.
35 |
--------------------------------------------------------------------------------
/docs/PyCharm_interpreter.md:
--------------------------------------------------------------------------------
1 | # Configuring your Python virtual environment PyCharm (Community and Pro)
2 |
3 | ## 1. Open your settings/preferences
4 |
5 |
6 |
7 | ## 2. Navigate to the Project Interpreter
8 |
9 |
10 |
11 | ## 3a. Select an existing interpreter
12 |
13 |
14 |
15 | If your desired version was found, click OK. If not, go on to 3b.
16 |
17 | ## 3b. Add a new interpreter
18 |
19 |
20 |
21 | ## 4. Add a system interpreter
22 |
23 |
24 | ## 5a. Select an existing system interpreter
25 |
26 |
27 |
28 | If your desired version was found, click OK. If not, go on to 5b.
29 |
30 | ## 5b. Find your system interpreter
31 |
32 |
33 |
34 | If you’re not sure where to find it, try one of the following locations
35 | (replace 3.9 or 39 with the desired version number):
36 |
37 | ### Windows (look for python.exe)
38 | - C:\Python39
39 | - C:\Program Files\Python39
40 | - C:\Users\username\AppData\Local\Programs\Python\Python39-XX
41 |
42 | ### Mac (look for python3.9 or python3)
43 | - /usr/local/bin/
44 | - /Library/Frameworks/Python.framework/Versions/3.9/bin/
45 | - /usr/local/Cellar/python/3.9.X_X/bin/
46 | - /Users/username/anaconda/bin/
47 | - /anaconda3/bin/
48 |
49 | ### Linux (look for python3.9 or python3)
50 | - /usr/bin/
51 | - /usr/local/bin
--------------------------------------------------------------------------------
/docs/WININSTALL.md:
--------------------------------------------------------------------------------
1 | ## Installing Python on Windows
2 | The Python installer for Windows doesn't use the optimal default settings.
3 | Follow these instructions when running the installer.
4 | If you have already installed Python with the default settings,
5 | follow the instructions here instead: [add Python to the PATH variable](WINSETPATH.md)
6 |
7 | 1. Check the *Add Python to PATH* box
8 | 2. Choose the *Customize installation* option
9 |
10 |
11 | 3. Keep the default settings and click *Next*
12 |
13 |
14 | 4. Check the *Install for all users* box if you want Python accessible by all users.
15 | 5. Customize the install location: **C:\Python39** or whatever version number you're installing
16 | 6. Click *Install*
17 |
18 |
--------------------------------------------------------------------------------
/docs/WINSETPATH.md:
--------------------------------------------------------------------------------
1 | ## Windows set up instruction
2 | If you installed Python with the default options,
3 | you will probably need to add Python to the PATH variable.
4 | This let's your operating system know where to look for the Python executable
5 | when you try running it.
6 |
7 | To add Python to your PATH variable:
8 | 1. Find the path of **python.exe** on your system.
9 | [Look in these directories](PATH_LOCATIONS.md) or search for it.
10 |
11 | 1. Open *System Properties* and click on the *Advanced* tab
12 |
13 | 1. Click on *Environment Variables*
14 |
15 | 1. Under *System variables* find and click on the *Path* variable
16 |
17 | 1. In edit mode, go to the end of the line and add **;C:\Python39** or whatever folder *python.exe* is in.
18 | Note the semicolon before the path; this will separate it from the previous path.
19 |
20 | Follow the instructions [here](../README.md#4-make-sure-that-python-is-properly-installed)
21 | to check that the PATH variable was set properly.
22 |
23 | If you are having problems:
24 |
25 | Search the internet for "**Add python to path on Windows *10 / Vista / XP / etc***"
26 | to find instructions for your version of Windows.
27 |
--------------------------------------------------------------------------------
/docs/img/installer_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ariannedee/python-level-2/ed532c42bb2825529a438f8675dc16f2ca6eb756/docs/img/installer_1.png
--------------------------------------------------------------------------------
/docs/img/installer_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ariannedee/python-level-2/ed532c42bb2825529a438f8675dc16f2ca6eb756/docs/img/installer_2.png
--------------------------------------------------------------------------------
/docs/img/installer_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ariannedee/python-level-2/ed532c42bb2825529a438f8675dc16f2ca6eb756/docs/img/installer_3.png
--------------------------------------------------------------------------------
/docs/img/pycharm_python_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ariannedee/python-level-2/ed532c42bb2825529a438f8675dc16f2ca6eb756/docs/img/pycharm_python_1.png
--------------------------------------------------------------------------------
/docs/img/pycharm_python_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ariannedee/python-level-2/ed532c42bb2825529a438f8675dc16f2ca6eb756/docs/img/pycharm_python_2.png
--------------------------------------------------------------------------------
/docs/img/pycharm_python_3a.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ariannedee/python-level-2/ed532c42bb2825529a438f8675dc16f2ca6eb756/docs/img/pycharm_python_3a.png
--------------------------------------------------------------------------------
/docs/img/pycharm_python_3b.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ariannedee/python-level-2/ed532c42bb2825529a438f8675dc16f2ca6eb756/docs/img/pycharm_python_3b.png
--------------------------------------------------------------------------------
/docs/img/pycharm_python_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ariannedee/python-level-2/ed532c42bb2825529a438f8675dc16f2ca6eb756/docs/img/pycharm_python_4.png
--------------------------------------------------------------------------------
/docs/img/pycharm_python_5a.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ariannedee/python-level-2/ed532c42bb2825529a438f8675dc16f2ca6eb756/docs/img/pycharm_python_5a.png
--------------------------------------------------------------------------------
/docs/img/pycharm_python_5b.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ariannedee/python-level-2/ed532c42bb2825529a438f8675dc16f2ca6eb756/docs/img/pycharm_python_5b.png
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | requests
2 | beautifulsoup4
3 |
--------------------------------------------------------------------------------