Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:deletes all the vowels,inserts a character "." before each consonant,replaces all uppercase consonants with corresponding lowercase ones.Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.Help Petya cope with this easy task.InputThe first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.OutputPrint the resulting string. It is guaranteed that this string is not empty.ExamplesinputCopytouroutputCopy.t.rinputCopyCodeforcesoutputCopy.c.d.f.r.c.sinputCopyaBAcAbaoutputCopy.b.c.b
Question
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:deletes all the vowels,inserts a character "." before each consonant,replaces all uppercase consonants with corresponding lowercase ones.Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.Help Petya cope with this easy task.InputThe first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.OutputPrint the resulting string. It is guaranteed that this string is not empty.ExamplesinputCopytouroutputCopy.t.rinputCopyCodeforcesoutputCopy.c.d.f.r.c.sinputCopyaBAcAbaoutputCopy.b.c.b
Solution
This problem can be solved by following these steps:
-
First, we need to convert the input string to lowercase. This can be done using the
lower()function in Python. -
Next, we need to remove all the vowels from the string. We can do this by iterating over the string and checking if each character is a vowel. If it is, we skip it. If it's not, we add it to a new string. In Python, we can use a for loop and the
inkeyword to check if a character is in a string of vowels. -
After removing the vowels, we need to add a "." before each consonant. We can do this by iterating over the string of consonants and adding a "." before each one.
-
Finally, we return the resulting string.
Here is a Python solution for the problem:
def process_string(s):
s = s.lower()
vowels = 'aoyeui'
result = ''
for char in s:
if char not in vowels:
result += '.' + char
return result
# Test the function
print(process_string('tour')) # Should print ".t.r"
print(process_string('Codeforces')) # Should print ".c.d.f.r.c.s"
print(process_string('aBAcAba')) # Should print ".b.c.b"
This function works by first converting the input string to lowercase. Then it creates an empty string result to store the resulting string. It iterates over each character in the input string, and if the character is not a vowel, it adds a "." and the character to result. Finally, it returns result.
Similar Questions
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.InputEach of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.OutputIf the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.ExamplesinputCopyaaaaaaaAoutputCopy0inputCopyabsAbzoutputCopy-1inputCopyabcdefgAbCdEfFoutputCopy1
Write a program that will take one string as input. The program will then remove vowels a, e, i, o, u (in lower or upper case) from the string. If there are two or more than two vowels that occur together then the program shall ignore all of those vowels.Sample input Cat Sample output CtSample input HeelSample output Heel
Q) Write a program to input a string and convert it into uppercase and print the pair of vowels and number of pair of vowels occurring in the string. Example: Input: "BEAUTIFUL BEAUTIES " Output : Pair of vowels: EA, AU, EA, AU, IE No. of pair of vowels: 5
Write a function that takes a string as input and returns a new string with all the vowels removed.
letter countWrite a C program that will analyze a line of text and will print the number of words, the number of consonants, and the number of vowels in the text.Testcase:Input:Programming is fun!Output:3 // Number of words:11 // Number of consonants:5 // Number of vowels:
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.