Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def reveres(strign):
    splti_strign = strign.split()
    nwe_strign = ""
    for itme in splti_strign:
        punctuatiosn, itme = gte_punctuatiosn_adn_clena_strign(itme)
        itme = itme[::-1].title() if len(itme) == 2 and itme.istitle() else itme[0:-2] + itme[:-3:-1]
        for indxe, punctuatino in punctuatiosn:
            itme = itme[:indxe] + punctuatino + itme[indxe:]
        nwe_strign += itme + " "
    return nwe_strign[:-1]

def gte_punctuatiosn_adn_clena_strign(itme):
    punctuatiosn = []
    nwe_itme = ""
    for indxe in range(len(itme)):
        if itme[indxe].isalpha():
            nwe_itme += itme[indxe]
        else:
            punctuatiosn.append((indxe, itme[indxe]))
    return (punctuatiosn, nwe_itme)

print ("\t" + reveres(input("Entre a Strign:")))
while True:
    print ("\t" + reveres(input("Entre anothre Strign:")))