-2
10) Make an algorithm that checks whether a given value is a String.
valor = str(input("Informe um valor: "))
if(type(valor) == str):
print("É uma String!")
In Pycharm IDLE or Python Console, type:
valor = "João"
type(valor)
he returns:
<class 'str'>
I Googled and heard about a function isinstance()
11) Make an algorithm that checks whether a given value is of the decimal type.
valor = input("Informe um valor: ")
if(isinstance(valor, float)):
print("É um decimal!")
else:
print("Não é um decimal!")
The above code of question 11 results in a wrong output, for if I type 3, or 3.2, in both it returns "It is 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 managed to do 14 exercises of 18, but these 2 and more other 2 that maybe I post later, I could not.
input
always returns a string. To check if this string contains a value that represents a number, you use something like this: https://answall.com/q/210010/112052– hkotsubo