1

the question requiers that i don't use the uppercase function and that french characters turn into non accsented uppercase like 'é' turns to 'E' here's what i came with

def Maj(s):
    l= list("âàéèêëïîôüûüÿ")
    r=''
    for char in s:
        if 65 <= ord(char) >= 90:
            r += chr(ord(char)-32)
        elif char in l :
            if 0 <= l.index(char) < 1:r += "A"
            if 2 <= l.index(char) < 6:r += "E"
            if l.index(char)== 6: r+="O"
            if 7 <= l.index(char) < 10 : r+= "U"
            if l.index(char)== 10: r+="Y"
        else:
            r += char
    return r

but it instead returns like this

>>>Maj("é")
'É'
  • Check this post https://stackoverflow.com/questions/517923/what-is-the-best-way-to-remove-accents-normalize-in-a-python-unicode-string – psycoxer May 21 '21 at 12:20

1 Answers1

2

Your issue is that you first check if the character is lesser than 65 or greater than 90, so it won't check the other condition: "à" ascii value for example is 224

def Maj(s):
    l= list("âàéèêëïîôüûüÿ")
    r=''
    for char in s:
        if char in l :
            if 0 <= l.index(char) < 2: r += "A"
            if 2 <= l.index(char) < 6:r += "E"
            if l.index(char)== 6: r+="O"
            if 7 <= l.index(char) < 10 : r+= "U"
            if l.index(char)== 10: r+="Y"
        elif 65 <= ord(char) >= 90:
            r += chr(ord(char)-32)
        else:
            r += char
    return r

Oh and you've got issues with your indexing. Try: Maj("ï")

Achille G
  • 748
  • 6
  • 19