-3
I have to make a code that prints names with more than 7 letters I’m using the pycharm my code is as follows::
nome = input("Digite os nomes separados por vírgula: ")
nomes = nome.split(',')
def imprime_nome_com_7_letras(nomes):
print("nomes com mais de 7 letras")
print([nome for nome in nomes if len(nome) == 7])
imprime_nome_com_7_letras(nomes)
if anyone can help me thank you.
What’s the doubt? The code you wrote even makes sense, the only detail is that it is displaying only names with EXACTLY 7 letters, as it did
len(nome) == 7
, but that is not what is requested in the.– Woss
Your code will receive more than one name. The method
split()
returns a list, where each item in that list is a word. For you to validate item by item from a list,for nome in nomes:
to check the size of the stringif len(nome) > 7: print(nome)
– gorn
Although the function is not implemented according to Python standards, if you replace
len(nome) == 7
forlen(nome) >= 7
, you will already have the desired result. However, I suggest studying a little more about the function structures.– Solkarped