1
I have an input with the name "city" which is a string and I need to make sure that if the user enters a number or does not type anything he receives an error message, as I could do?
Follows the code
import requests
import json
from googletrans import Translator
class Temperatura():
while True:
cidade = input("Escreva sua cidade para consultar o tempo: ")
requisicao = requests.get("http://api.openweathermap.org/data/2.5/weather?q=" + cidade +
"&appid=KEY")
tempo = json.loads(requisicao.text)
des = tempo['weather'][0]['description']
hu = tempo['main']['humidity']
t = tempo['main']['temp'] -273.15
#tradução
translator = Translator()
des_t = translator.translate(des, dest='pt').text
print('Condição do tempo:', des_t,',temperatura de', round(t),'graus','e umidade a',hu,'%')
That class
Temperatura
has awhile
just like that? No methods?– Woss
yes, but further down I have another input, which depending on the answer it to the class and starts another.
– Filipe.C
It seems that you used class the wrong way there. This could be a function only.
– Woss
Already corrected, thanks for the idea.
– Filipe.C
There are several other mistakes there, even if you change
class
fordef
no request will be made. recommend a better reading on the doc of the api. besides these two links for references classes and function– Tmilitino