s = input()
s.lower()
for i in range (0, len(s)):
if(s[i] in "aoyeui"):
s.replace(s[i], '')
for i in range(0, len(s)):
s.replace(s[i], '.' + s[i])
print(s)
this code should remove all the vowels and split the string by '.'
s = input()
s.lower()
for i in range (0, len(s)):
if(s[i] in "aoyeui"):
s.replace(s[i], '')
for i in range(0, len(s)):
s.replace(s[i], '.' + s[i])
print(s)
this code should remove all the vowels and split the string by '.'
Lets comment it line by line:
s = input () #wrong indentation
s.lower() # you have to assign it to s.
for i in range (0, len(s)): # range(0, x) is the same as range(x)
if (s[i] in "aoyeui"): # ok
s.replace(s[i], '') # strings are not mutable so replace does not modify the string. You have to assign it to s
# splitting can be done much easier :)
for i in range(0, len(s)):
s.replace(s[i], '.' + s[i]) # again you have to assign
print(s) # ok
Also I have just noticed that there is one more problem with your code. When you replace vowels string length changes and it can cause multiple problems. You should not in general iterate by index when the length changes. So the correct code should look like:
s = input ()
s = s.lower()
for vowel in "aoyeui":
s = s.replace(vowel, '')
s = '.'.join(list(s)) # this is how to separate each character with a dot (much easier eh?)
print(s)
str
is immutable. All operations on it create a new str
.
You want to reassign s
when you use replace
. Or lower
.
s = s.lower()
s = s.replace(s[i], '')
s.lower()
should be assigned to s
otherwise the original string will remain intact.
I rewrote a working code. Hope it helps you:
s = str(input("Text: "))
s = s.lower()
t =""
for char in s:
if char not in "aoyeui":
t+=char
t = t.split('.')
for i in t:
print(i)