python-workout icon indicating copy to clipboard operation
python-workout copied to clipboard

e07b1_capital.py do not check if the first character is a vowel and uppercase

Open khoi-thinh opened this issue 4 years ago • 1 comments

As a result, if the word we check is: Octopus, then output should be Uboctubopubus, not Octubopubus. I think the code can be something like this.

def ubbi_dubbi(string):
    output = []
    if string[0].lower() in "aiueo":
        result = f'ub{string[0]}'
    else:
        result = f'{string[0]}'   

    if string[0].isupper():
        output.append(result.capitalize())
    else:
        output.append(result)    

    for each in string[1:]:
        if each in "aiueo":
            output.append(f'ub{each}')
        else:
            output.append(each)    
    return ''.join(output)

khoi-thinh avatar Apr 16 '21 09:04 khoi-thinh

Hello @khoi-thinh , your solution looks a little bit complicated. To fix problem is enough to add ".lower()"

def ubbi_dubbi_caps(word):
    """Ask the user to enter a word,
and return the word's translation into Ubbi Dubbi.
If the input word is capitalized, then the output
word should be, too.
"""
    output = []
    for letter in word:
        if letter**.lower()** in 'aeiou': # <<<<<<<<<<<<<<<<<
            output.append(f'ub{letter}')
        else:
            output.append(letter)

    if word[0] in string.ascii_uppercase:
        output[0] = output[0].capitalize()

    return ''.join(output)

Andrey-Ilyichev avatar Nov 21 '21 09:11 Andrey-Ilyichev