10) Make an algorithm that checks if a given value is a String.
valor = str(input("Informe um valor: "))
if(type(valor) == str):
print("É uma String!")
In the IDLE or Python Console of PyCharm, if I type:
valor = "João"
type(valor)
it returns:
<class 'str'>
I researched Google and heard about a isinstance ()
11) Make an algorithm that checks if a given value is a decimal type.
valor = input("Informe um valor: ")
if(isinstance(valor, float)):
print("É um decimal!")
else:
print("Não é um decimal!")
The code above, from question 11, results in a wrong output, because if I type 3, or 3.2, in both it returns "Not a decimal!"
I would like to know the answers to these 2 questions .. (use Python 2.7 or Python 3.7, both are in Virtual Environments with Anaconda)
I was able to do 14 exercises of 18, but these 2 and more 2 that maybe I post later, I could not.