How can I remove vowels | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I remove vowels

Remove all the vowels in the message, unless the word starts with a vowel. Duplicate spaces should also be removed. They would also like to have the message in Uppercase letters and before each message they include the club name (with no vowels removed). The user should also be informed of the length of the message. Develop a program that reads in a normal description of a message and displays the corresponding Bulk SMS in UPPERCASE letters. The program must continue to accept adverts until the user indicates that they would like to terminate or exit the program. my attempt: Club_Name = " " message1 = " " while Club_Name != "#" or message1 != "#": Club_Name = input("Enter your group or club name[ENTER (#) TO EXIT]: ") message1 = input("Enter a message[ENTER (#) TO EXIT]: ") print() def BulkSMS(): newstring = " " for i in range(len(message1)): pos = message1.find(".") newstring = message1[:pos+1]+message1[pos+1:].strip() for i in message1: if i == "a" or i == "e" or i == "i" or i == "o" or i == "u": continue for i in message1: if i.startswith("a") or i.startswith("e") or i.startswith("i") or i.startswith("o") or i.startswith("u"): continue return newstring.upper().strip() print(BulkSMS())

16th Jun 2021, 11:11 AM
Minenhle Simphiwe
Minenhle Simphiwe - avatar
4 Answers
+ 3
Minenhle Simphiwe , nice task to do for you, and i will give you some help step by step: [part 1] (1) function def BulkSMS() is placed inside the while loop, this should not be done. place the complete function on top of your code (2) in the BulkSMS() you have 3 for loops running in sequence - first loop: not clear why you are searching for a dot "." but the loop seems to do nothing? - second loop: it is looping through the message but it is doing nothing at all - third loop: same issue as with second loop -> as all 3 loops do nothing we could remove them, OR - rework them for what they should do some thoughts: - take message input and convert it all to upper and split it to space boundaries. this will create a list of words - take club input use the list with the message words. create a new empty output list. iterate through the words list and do: - if the word starts with a vowel: append it to the output list else remove all vowels in this word, then append it to output list
16th Jun 2021, 2:46 PM
Lothar
Lothar - avatar
+ 3
Minenhle Simphiwe , yes, i understand this. but this can be also be done in different way: ▪︎put the function out of the loop ▪︎place input inside the loop ▪︎modify function so that if could take n arguments ▪︎call the function with n arguments
20th Jun 2021, 1:12 PM
Lothar
Lothar - avatar
+ 1
@lothar Thanks let me try to do that. I placed the def function inside the loop for it to repeat prompting the user.
17th Jun 2021, 11:05 PM
Minenhle Simphiwe
Minenhle Simphiwe - avatar
0
You can use python regex library to remove double spaces and vowels easily! import re a=input() b=re.sub(" "," ",a) c=re.sub("(?<=.)[aeiou]","",b) print(c) Here "(? <=.)[aeiou]" will only match character 'a' or 'e' or 'i' or 'o' or 'u' if it is preceded by some other character .
16th Jun 2021, 12:19 PM
Abhay
Abhay - avatar