0
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 '.'

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • 2
    Since we're not privy to the screen you're writing the code in, a pedant may say "indentation"... – Makoto Dec 05 '14 at 22:05
  • possible duplicate of [Remove specific characters from a string in python](http://stackoverflow.com/questions/3939361/remove-specific-characters-from-a-string-in-python) – Peter Wood Dec 05 '14 at 22:27

3 Answers3

3

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)
Piotr Dabkowski
  • 5,661
  • 5
  • 38
  • 47
1

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], '')
Makoto
  • 104,088
  • 27
  • 192
  • 230
0

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) 
Omid
  • 2,617
  • 4
  • 28
  • 43