#!usr/bin/env python
def vocales(string):
if "A" or "a" or "E" or "e" or "I" or "i" or "O" or "o" or "U" or "u" in string:
nvocalesami = (string.count("a"))
nvocalesama = (string.count("A"))
nvocalesemi = (string.count("e"))
nvocalesema = (string.count("E"))
nvocalesimi = (string.count("i"))
nvocalesima = (string.count("I"))
nvocalesomi = (string.count("o"))
nvocalesoma = (string.count("O"))
nvocalesumi = (string.count("u"))
nvocalesuma = (string.count("U"))
part1 = (nvocalesami + nvocalesama + nvocalesemi + nvocalesema + nvocalesimi + nvocalesima)
part2 = (nvocalesomi + nvocalesoma + nvocalesumi + nvocalesuma)
todo = (part1 + part2)
return ("Hay",todo,"vocales en la frase")
else:
return("No hay vocales en la frase")
I have a problem with this code when using the vowels function with an argument without vowels, for example:
Departure
vocales("r")
Hay 0 vocales en la frase
Why doesn't "There are no vowels in the sentence" come out?
This code works, the problem was that you didn't wrap the if expression with parentheses.
use the following code
The problem is that it
if
is evaluating eachor
as several individual logical conditions and not as a single compound condition, that is, it is evaluating each operand, and finding the first operand to be true enters the condition.You can prove this by leaving only the following condition:
And it's going to run the same way your code is currently running.
The problem is easily solved by enclosing the conditions in parentheses, as follows:
And there you will get the output: