-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomework4.py
49 lines (36 loc) · 1001 Bytes
/
homework4.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import requests
from bs4 import BeautifulSoup
os.system("clear")
url = "https://www.iban.com/currency-codes"
countries = []
request = requests.get(url)
soup = BeautifulSoup(request.text, "html.parser")
table = soup.find("table")
rows = table.find_all("tr")[1:]
for row in rows:
items = row.find_all("td")
name = items[0].text
code =items[2].text
if name and code:
country = {
'name':name.capitalize(),
'code': code
}
countries.append(country)
def ask():
try:
choice = int(input("#: "))
if choice >= len(countries) or choice <0:
print("Choose a number from the list.")
ask()
else:
country = countries[choice]
print(f"You chose {country['name']}\nThe currency code is {country['code']}")
except ValueError:
print("That wasn't a number.")
ask()
print("Hello! Please choose select a country by number:")
for index, country in enumerate(countries):
print(f"#{index} {country['name']}")
ask()