Click here to Skip to main content
15,905,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I expect my code to ask the input from the user once, but it asks it like 4 times and doesn't go to the next one.It starts asking from the second program thing "def translate word" and then goes to the top and asks multiple times to enter a word and then stops doing anything and doesn't go to the most bottom one left.

What I have tried:

"""
should take in a single parameter which is assumed to be a single word
search the word for the index location of the first vowel (a, e, i, o, u)
return the index value of the first vowel, or a negative 1 if there is no vowel
"""
def findFirstVowel(word):
original = input('Enter a word:')
word = original.lower()
first = word[0]
vowel = ('a','e','i','o','u')
if len(original) > 0 and original.isalpha():
if first in vowel:
print (first)
else:
print ('-1')
else:
print("empty...")


"""
takes in a single parameter which is assumed to be a single word
sends that word to findFirstVowel() and stores the result sent back
uses the result of findFirstVowel() to see which of the three rules apply
uses this information to modify the word appropriately
returns the string representing the translated word
"""


def translateWord():
lst = ['sh', 'gl', 'ch', 'ph', 'tr', 'br', 'fr', 'bl', 'gr', 'st', 'sl', 'cl', 'pl', 'fl']
sentence = input('Type what you would like translated into pig-latin and press ENTER: ')
sentence = sentence.split()
for k in range(len(sentence)):
i = sentence[k]
if i[0] in ['a', 'e', 'i', 'o', 'u']:
sentence[k] = i+'way'
elif t(i) in lst:
sentence[k] = i[2:]+i[:2]+'ay'
elif i.isalpha() == False:
sentence[k] = i
else:
sentence[k] = i[1:]+i[0]+'ay'
return ' '.join(sentence)

def t(str):
return str[0]+str[1]

if __name__ == "__main__":
x = translateWord()
print(x)


"""
accept a single parameter, assumed to be one sentence
assume there are no punctuation marks IN it
assume there is a period at the end of the sentence
removes the period from the sentence and changes all to lowercase letters
breaks the sentence into individual words using split ()
use the translateWord() function to translate each word printing each word as it goes along

"""
def pigLatinTranslator(sentence):
sentence=input('Please enter a sentence to translate it:')
sentence=sentence.split()
for k in range(len(sentence).lower):
i=sentence[k]
if i[0] in ['a', 'e', 'i', 'o', 'u']:
sentence[k] = i+'way'
elif t(i) in lst:
sentence[k] = i[2:]+i[:2]+'ay'
elif i.isalpha() == False:
sentence[k] = i
else:
sentence[k] = i[1:]+i[0]+'ay'
return ' '.join(sentence)
def t(str):
return str[0]+str[1]

if __name__ == "__main__":
x = pigLatinTranslator()
print(x)
Posted
Comments
Richard MacCutchan 14-Apr-18 4:13am    
That is three different programs, which one is causing the problem?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900