vendredi 2 avril 2021

Netacad course, I'm being bamboozled with "for letter in userWord" statement. appreciate your help TIA

I'm a newbie in Python and I'm currently studying from Netacad free courses and there's this lab exam, that design a vowel eater, the program uses: -a for loop; -the concept of conditional execution (if-elif-else) -the continue statement.

Luckily I found some code (ctto) and try to edit some part to study it. if someone happens to passed or got this exam, I would gladly appreciate your help (note: this is the second exam which the output must be displayed on one line) so, Here's the code:

userWord = input("Type Here: ")
userWord = userWord.upper()
for letter in userWord:
    if letter == "A":
        continue
    if letter == "E":
        continue
    if letter == "I":
        continue
    if letter == "O":
        continue
    if letter == "U":
        continue

    print(letter, end="")

else:
    print(letter)

I understand it and it works just fine, So my questions are:

-It does takes away the vowel but not all, sometimes when the word is long there will be a remaining vowel on the last part of it, or if the last letter is consonant it will be duplicated did I violated some code positioning or does my code is not really the perfect solution? -also the when does the 'if and in' statements produce a vertical output? or horizontal? tho I managed to make it horizontal, and quite understand it, but I haven't learned the exact underlying principle.

My apologies for the long post, and maybe for idiotic question, but I would gladly appreciate your help. Thankyou!

Aucun commentaire:

Enregistrer un commentaire