Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Uppercase problem
#1
Hi,
I've been learning python for a week and today i started doing a translator in an invented language. The problem is that if i write an upper letter, it is translated as a lower letter.
Here is the code



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


print(translate(input("Enter a phrase")))
Reply
#2
def translate(phrase):
    translation = ""
    for letter in phrase:
        if letter.lower() in "aeiou": # if letter is lower
            if letter.isupper(): # this can never be true, in order to get here, letter must have been a vowel and lower case!
Reply
#3
Ok,
So I should remove the lower fuction.
Sorry for asking again but it’s my first week coding and I amb kind of a noob.
Reply
#4
Actually, my previous post was incorrect.
the letter upper letter is lowered in scope for the if statement only. if letter.lower() in "aeiou":
your code works:
[inline]Enter a phrase Everyone
Gvgrygng[/inline]
Reply
#5
Ok,
Thanks a lot
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using re to find only uppercase letters ranbarr 6 3,295 May-31-2021, 03:19 PM
Last Post: ranbarr
  Check if string is uppercase or lowercase and eliminate Wolfpack2605 1 4,749 Jan-01-2018, 05:03 AM
Last Post: Mekire

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020