جواب «The Warmest City» چالش 4 از جلسهی 11
سؤال
اسم شهرها را از https://weather.test/cities بگیر. بعد برای هر شهر (به همان ترتیب) دمای امروزش را از today?city=... بپرس و یک خط Isfahan: 17 چاپ کن. در آخر گرمترین شهر را با دمایش چاپ کن:Warmest: Shiraz (22)
همهی درخواستها با quiet=True.
راهنما
در حلقه: r = ask(f"https://weather.test/today?city={city}", quiet=True)، temp = r.json["temp"]، چاپ، و if temp > best_temp: هر دو متغیر را عوض کن.
یک جواب درست
from server import ask
cities = ask("https://weather.test/cities", quiet=True).json
best_city = ""
best_temp = -100
for city in cities:
r = ask(f"https://weather.test/today?city={city}", quiet=True)
temp = r.json["temp"]
print(f"{city}: {temp}")
if temp > best_temp:
best_city = city
best_temp = temp
print(f"Warmest: {best_city} ({best_temp})")
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن