repl.it
@joe_simop_8/

English to Pig Latin

Python

No description

fork
loading
Files
  • main.py
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from termcolor import colored,cprint
cprint('Welcome to the pig latin translator!', 'yellow')
cprint('Enter the English form of your string below:', 'yellow')


vowels = ['a', 'e', 'i', 'o', 'u']

sect = input()
splitsect = sect.split(' ')
num_elements = len(splitsect)

for i in range (0,num_elements):
    
    vt = False
    found_vowel = False
    
    for j in range(0, len(vowels)):
        if vowels[j] in splitsect[i]:
            vt = True
            if found_vowel == False:
                vowel_val = j
                found_vowel = True
            if found_vowel == True:
                first_vowel = 0
                while splitsect[i][first_vowel] != vowels[vowel_val] and splitsect[i][first_vowel] != vowels[j]:
                    first_vowel += 1
                if splitsect[i][first_vowel] == vowels[vowel_val]:
                    pass
                else:
                    vowel_val = j
    if vt == True:
        if vowels[vowel_val] == splitsect[i][0]:
            splitsect[i] = splitsect[i] + 'ay'
        else:
            a = 0
            temp = ''
            while splitsect[i][a] != vowels[vowel_val]:
                temp = temp + splitsect[i][a]
                a = a+1
            splitsect[i] = splitsect[i][a:] + temp + 'ay'
    else:
        splitsect[i] = splitsect[i][1:] + splitsect[i][0] + 'ay'
        
final_str = ''

for i in range(0,len(splitsect)):
    final_str = final_str + splitsect[i] + ' '
print()
cprint(final_str, 'cyan')

#If you want the code commented, let me know!
            
?