Answer the question
In order to leave comments, you need to log in
Yandex Practicum. Lesson 6 "Error Handling". I can't find the error in the code. What is done wrong?
import requests
cities = [
'Омск',
'Калининград',
'Челябинск',
'Владивосток',
'Красноярск',
'Москва',
'Екатеринбург'
]
def make_url(city):
# в URL задаём город, в котором узнаем погоду
return f'http://wttr.in/{city}'
def make_parameters():
params = {
'format': 2, # погода одной строкой
'M': '' # скорость ветра в "м/с"
}
return params
def what_weather(city):
# Напишите тело этой функции.
# Не изменяйте остальной код!
try:
request = requests.get(make_url(city), params=make_parameters())
if request.status_code == 200: return request.text
else: return '<ошибка на сервере погоды>'
except requests.ConnectionError : return '<сетевая ошибка>'
print('Погода в городах:')
for city in cities:
print(city, what_weather(city))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question