Note that there are some explanatory texts on larger screens.

plurals
  1. POTranslating sentences into pig latin
    primarykey
    data
    text
    <p>SO i have this assignment to translate multiple words into pig latin. assume that the user will always input lowercase and only letters and spaces.</p> <pre><code>#----------------global variables sentence = input("What do you want to translate into piglattin? ") sentence = list(sentence) sentence.insert(0, ' ') length = len(sentence) sentence.append(' ') pigLattin = sentence false = 0 true = 1 consonant = [] a = 0 b = 0 c = 0 d = 0 e = 0 f = 0 j = 0 x = 0 y = 0 #----------------main functions def testSpace(sentence, i): if sentence[i] == ' ': a = true else: a = false return a def testVowel(sentence, i): if sentence[i] == 'a' or sentence[i] == 'e' or sentence[i] == 'i' or sentence[i] == 'o' or sentence[i] == 'u' or sentence[i] == 'y': b = true else: b = false return b def testStartWord(sentence, i): x = 0 if sentence[i].isalpha() and sentence[i-1] == ' ': c = true x = 1 if x == 1 and sentence[i] != 'a' and sentence[i] != 'e' and sentence[i] != 'i' and sentence[i] != 'o' and sentence[i] != 'u' and sentence[i] != 'y': c = true else: c = false return c def testWordEnd(sentence, i): if sentence[i].isalpha() and sentence[i+1] == ' ': d = true else: d = false return d #----------------main loop for i in range(1,length): x = 0 space = testSpace(sentence, i) vowel = testVowel(sentence, i) word = testStartWord(sentence, i) end = testWordEnd(sentence, i) if vowel == false and space == false and word == true: e = i consonant.append(sentence[i]) pigLattin.pop(e) f = f + 1 if end == true: consonant.append('a') consonant.append('y') consLength = len(consonant) for x in range(consLength): y = i + j - f pigLattin.insert(y,consonant[x]) j = j + 1 del consonant[:] pigLength = len(pigLattin) for b in range (pigLength): print(pigLattin[b], end='') </code></pre> <p>this is what i have so far. it gets kinda messy when trying to remove items. im sort of stuck here and its not working.</p> <p>OK i got it working now this is an updated version</p> <pre><code>sentence = input("Please enter a sentence: ") vowels = ("a", "e", "i", "o", "u", "A", "E", "I", "O", "U") words = sentence.split() count = 0 def find_vowel(word): for i in range(len(word)): if word[i] in vowels: return i return -1 for word in words: vowel = find_vowel(word) if(vowel == -1): print(word, ' ', end='') elif(vowel == 0): print(word + "ay", ' ', end='') else: print(word[vowel:] + word[:vowel] + "ay", ' ', end='') </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload