Skip to content
TORNLIFE More

Python[solved]

Started by AlvaroMorata [818413] on in Technology.

3 replies · 76 views · thread synced · 4 days ago · View on torn.com
About this thread

Posts archived: 4 / 4 posts (100%) · the total is Torn's reply count + the opening post at the last fetch

Counted by TornLife from the archived posts.

Archived posts
4
Discussion span
→
People posting
4
Likes on archived posts
4
Authority score
7 / 100
Historical score
12 / 100
Story score
27 / 100
Engagement score
44 / 100
AlvaroMorata [818413]

Thank you Astral. I've gotten it a while back. My solution is below :)

Write a program that uses a for-loop to ask a user to enter 5 words. The program will then display all the words entered that starts with a vowel only. Your program must use the function start_vowel defined in Question 5 .

Sample output:

Enter a word : Apple

Enter a word : eagle

Enter a word : horse

Enter a word : Hamster

Enter a word : Ostrich

Word that begins with vowels are ['Apple', 'eagle', 'Ostrich']



#Function
def start_vowel(word):
if word.startswith(('a','e','i','o','u')):
return True
return False

#Main program
wordList = []
for word in range(5):
word = input("Enter a word : ").lower()
if start_vowel(word):
wordList.append(word)
else:
pass

print("Word that begins with vowels are {} ".format(wordList))


Astral [300312]

Well it's much longer to type if you want to do it like that: if word[0] == 'A' or word[0] == 'a' or word[0] == 'E' .. etc

Shorter to do: if word[0] in 'aeiouAEIOU':

So the first letter is any of those in the string, return true.



The complete program, would need an extra for loop to run your function:



def start_vowel(word):
if word[0] in 'aeiouAEIOU':
return True
else:
return False

wordList = []
for word in range(5):
wordList.append(raw_input("Enter a word : "))

print "Word that begins with vowels are: "
for word in wordList:
if start_vowel(word):
print word




styne [730205]

As much as I want to help you out on this, I think I'd be doing your homework for you and that's not the best.