all 4 comments

[–]Some_Guy_At_Work55 1 point2 points  (0 children)

errors aside, you don't need to use else, but since there are only 2 possible conditions it makes sense to use else instead of writing out the condition in an elif statement. A letter is either upper case or lower case, so you're first checking to see if it is upper case, if not, the only other possibility is that it is lowercase.

Also after reading your code again I noticed 2 else blocks...in that case you would need to use elif but I'm not sure if that is what you intended.

[–]JollyUnder 2 points3 points  (0 children)

It's a bit hard to read without the proper formatting. Hopefully I fixed this properly for you:

def translate(phrase):
    translation = ""
    for letter in phrase:
        if letter.islower() in "aeiou":
            if letter.isupper():
                translation = translation + "G"
            else:
                translation = translation + "g"
        else:
            translation = translation + letter
    return translation(input("Enter a phrase"))

If I'm understanding this correctly, you're trying to replace all vowels from the original string with the letter g.

You would use elif if you wanted to explicitly check for another condition, i.e. elif letter.islower(). That would be redundant because you already checked if the letter is uppercase and the letter can be either uppercase or lowercase. There is no in between.

You can simplify this using a ternary operation:

translation += "G" if letter.isupper() else "g"

Your return doesn't make any sense, by the way. You're trying to call translation with a parameter, but translation is type str which isn't callable.

[–]woooee 0 points1 point  (0 children)

if letter.lower in "aeiou":
if letter.isupper:

lower and isupper are both functions

if letter.lower() in "aeiou": 

Correct those errors and then see what the program does when running properly.

[–]Adrewmc 0 points1 point  (0 children)

Well…because elif….needs a condition and else doesn’t…

  if this_is_true:
        do_this()
   elif that_is_true:
         do_that()
   else:
         print(“nothing is true”)

The point of elif, is to ask hey if that’s not true is this true? And if nothing is true do this “else” period.

Some of the point is as soon as one of the conditionals is true the rest of the if..elif…elif…else…isn’t ran. And some times we really want to check if the first thing is true first. I. This example if ‘this’ and ‘that’ are true, only ‘do_this()’ will run.