D
D
Doit2021-05-04 19:30:05
Python
Doit, 2021-05-04 19:30:05

How to get the names of north, east, south from wind deg in degrees?

I tried it like this

wind = w.wind()
    w3 = wind['deg']
    w4 = itog

    c = range(337,380)
    c = range(0,22)
    cv = range(22,67)
    v = range(67,112)
    yv = range(112,157)
    y = range(157,202)
    yz = range(202,247)
    z = range(247,292)
    cz = range(292,337)

    if w3 == c:
        itog = 'С';
    elif w3 == cv:
    	itog = 'СВ';
    elif w3 == v:
    	itog = 'В';
    elif w3 == yv:
    	itog = 'ЮВ';
    elif w3 == y:
    	itog = 'Ю';
    elif w3 == yz:
    	itog == 'ЮЗ';
    elif w3 == z:
    	itog == 'З';
    elif w3 == cz:
    	itog == 'СЗ';

    answer = 'В городе '+message.text+' направление ветра ' + w4

    if message.text == message.text:
    	bot.send_message(message.from_user.id, answer);

It gives this UnboundLocalError: local variable 'itog' referenced before assignment
In general, tell me how bad everything is with me and how best to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kisaa, 2021-05-05
@stik3228

winddirections = ("северный", "северо-восточный", "восточный", "юго-восточный", "южный", "юго-западный", "западный", "северо-западный")
direction = int((degrees + 22.5) // 45 % 8)
print(winddirections[direction])

Y
Yupiter7575, 2021-05-04
@yupiter7575

w4 = itog
you first used the variable
then you created it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question