-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9.superhero.py
More file actions
38 lines (26 loc) · 1.43 KB
/
9.superhero.py
File metadata and controls
38 lines (26 loc) · 1.43 KB
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
# Кто самый умный супергерой? Есть API по информации о супергероях. Нужно определить кто самый умный(intelligence)
# из трех супергероев- Hulk, Captain America, Thanos. Для определения id нужно использовать метод /search/name
#
# Токен, который нужно использовать для доступа к API: 2619421814940190.
# Таким образом, все адреса для доступа к API должны начинаться с https://superheroapi.com/api/2619421814940190/.
import requests
superheros = ["Hulk", "Thanos", "Captain America"]
def GetSuperHerointelligence(superhero, token=2619421814940190):
response = requests.get(
"https://superheroapi.com/api/" + str(token) + "/search/" + superhero
)
response.raise_for_status()
results = response.json()
for res in results["results"]:
if res["name"] != superhero:
continue
return res["powerstats"]["intelligence"]
intelhero = 0
intelheroname = ''
for superhero in superheros:
intel = int(GetSuperHerointelligence(superhero))
print(f'У {superhero} уровень интеллекта {intel}')
if intel > intelhero:
intelhero = intel
intelheroname = superhero
print(f'Самый умный {intelheroname} с уровнем интеллекта {intelhero}')