|
23 | 23 | countries = [] |
24 | 24 |
|
25 | 25 | for row in rows: |
26 | | - data = row.find_all("td") |
27 | | - # name = Country name |
28 | | - name = data[0].text |
29 | | - # code = Currency code |
30 | | - code = data[2].text |
31 | | - if name and code: |
32 | | - # No universal currency = Currency code is empty |
33 | | - if name != "No universal currency": |
34 | | - country = {'name': name.capitalize(), 'code': code} |
35 | | - countries.append(country) |
| 26 | + data = row.find_all("td") |
| 27 | + # name = Country name |
| 28 | + name = data[0].text |
| 29 | + # code = Currency code |
| 30 | + code = data[2].text |
| 31 | + if name and code: |
| 32 | + # No universal currency = Currency code is empty |
| 33 | + if name != "No universal currency": |
| 34 | + country = {'name': name.capitalize(), 'code': code} |
| 35 | + countries.append(country) |
36 | 36 |
|
37 | 37 |
|
38 | 38 | print("Hello! Please choose select a country by number:") |
39 | 39 | # enumerate = 열거하다 / 기본적으로 인덱스 값을 포함해서 출력함 |
40 | 40 | for index_value, country in enumerate(countries): |
41 | | - print(f"#{index_value} {country['name']}") |
| 41 | + print(f"#{index_value} {country['name']}") |
42 | 42 |
|
43 | 43 |
|
44 | 44 | def restart(): |
45 | | - answer = str(input("Do you want to find more? y/n ")).lower() |
46 | | - if answer == "y" or answer == "n": |
47 | | - if answer == "y": |
48 | | - ask() |
49 | | - else: |
50 | | - print("OK. Bye!") |
51 | | - return |
| 45 | + answer = str(input("Do you want to find more? y/n ")).lower() |
| 46 | + if answer == "y" or answer == "n": |
| 47 | + if answer == "y": |
| 48 | + ask() |
52 | 49 | else: |
53 | | - print("Please answer `y` or `n`") |
54 | | - restart() |
| 50 | + print("OK. Bye!") |
| 51 | + return |
| 52 | + else: |
| 53 | + print("Please answer `y` or `n`") |
| 54 | + restart() |
55 | 55 |
|
56 | 56 |
|
57 | 57 | def ask(): |
58 | | - try: |
59 | | - # choose index_value |
60 | | - choice = int(input("#: ")) |
61 | | - if choice > len(countries): |
62 | | - print("Choose a number from the list.") |
63 | | - ask() |
64 | | - else: |
65 | | - country = countries[choice] |
66 | | - print(f"Country: {country['name']}🌏") |
67 | | - print(f"Currency: {country['code']}💲") |
68 | | - restart() |
69 | | - # input result = not int |
70 | | - except ValueError: |
71 | | - print("That wasn't a number. Please wirte a number.") |
72 | | - ask() |
| 58 | + try: |
| 59 | + # choose index_value |
| 60 | + choice = int(input("#: ")) |
| 61 | + if choice > len(countries): |
| 62 | + print("Choose a number from the list.") |
| 63 | + ask() |
| 64 | + else: |
| 65 | + country = countries[choice] |
| 66 | + print(f"Country: {country['name']}🌏") |
| 67 | + print(f"Currency: {country['code']}💲") |
| 68 | + restart() |
| 69 | + # input result = not int |
| 70 | + except ValueError: |
| 71 | + print("That wasn't a number. Please wirte a number.") |
| 72 | + ask() |
73 | 73 |
|
74 | 74 |
|
75 | 75 | ask() |
|
0 commit comments