Python Forum
Functions to remove vowels and extra blanks - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Functions to remove vowels and extra blanks (/thread-6341.html)

Pages: 1 2


Functions to remove vowels and extra blanks - RiceGum - Nov-17-2017

Example A:
Input:

Um cidadão ficou sem paciência ao esperar nas Finanças.

O âmbito do atentado foi grande. Ouve 56 vítimas. Que horror!

O coração foi o único órgão afetado, mas o doente não sobreviveu

.

Output:

m cdd fc sm pcnc sprr ns Fnnçs.

mbt d tntd f grnd. v 56 vtms. Q hrrr!

crç f nc rg ftd, ms dnt n sbrvv

Example B:
Input:

Ele já sabia que ia ser assim, tu é que achavas que não

.

Output:

l j sb q sr ssm, t q chvs q n

def isVowel(s):
if s in ('aeiouáéíóúàèìòùãõâêîôûAEIOUÁÉÍÓÚÀÈÌÒÙÃÕÂÊÎÔÛ'):

    return True
else:
    return False
def eraseVowels(cadeia):
    vogais ='aeiouáéíóúàèìòùãõâêîôûAEIOUÁÉÍÓÚÀÈÌÒÙÃÕÂÊÎÔÛ'
    nova_cadeia =''
    for car in cadeia:
        if car in vogais:
            nova_cadeia = nova_cadeia + ''
        else:
            nova_cadeia = nova_cadeia + car
    return nova_cadeia
def eraseExtraBlanks(s):
    while '  ' in s:
        s=s.replace('  ',' ')
        s.strip()

return s.strip()

x = input()
while x != '.':
    x = input()
    if x == '.':
        break
    if ('  ') in x:
        print(eraseExtraBlanks

print(eraseVowels)
I need the program to accept multiple strings until the user enters '.' then is should remove vowels and extra blanks(in case they exist) and show the results aas demonstrated in the examples


RE: Functions to remove vowels and extra blanks - heiner55 - Nov-17-2017

#!/usr/bin/env python3
import sys
def isVowel(s):
    if s in 'aeiouáéíóúàèìòùãõâêîôûAEIOUÁÉÍÓÚÀÈÌÒÙÃÕÂÊÎÔÛ':
        return True
    else:
        return False

def eraseVowels(cadeia):
    nova_cadeia =''
    for car in cadeia:
        if isVowel(car):
            nova_cadeia += ''
        else:
            nova_cadeia += car
    return nova_cadeia

def eraseExtraBlanks(s):
    while '  ' in s:
        s=s.replace('  ',' ')
        s.strip()
    return s.strip()

while True:
    x = input("input: ")
    if x == '.':
        break
    x = eraseExtraBlanks(x)
    x = eraseVowels(x)
    print(x)



RE: Functions to remove vowels and extra blanks - RiceGum - Nov-17-2017

Thank you it is working! But i need something that looks like this:
Example A:
Input:

Um cidadão ficou sem paciência ao esperar nas Finanças.

O âmbito do atentado foi grande. Ouve 56 vítimas. Que horror!

O coração foi o único órgão afetado, mas o doente não sobreviveu

.

Output:

m cdd fc sm pcnc sprr ns Fnnçs.

mbt d tntd f grnd. v 56 vtms. Q hrrr!

crç f nc rg ftd, ms dnt n sbrvv

Reads multiple strings and then gives me the result os them all in a row. Your solution only reads one string and gives me the output straight away.


RE: Functions to remove vowels and extra blanks - heiner55 - Nov-17-2017

I assume you can combine the two programs yourself.

#!/usr/bin/env python3
import sys

def multi_line_input():
    lines = ""
    while True:
        line = input("input: ")
        if line == '.':
            break
        else:
            lines += line + "\n"
    return lines


x = multi_line_input()
print(x)



RE: Functions to remove vowels and extra blanks - RiceGum - Nov-17-2017

That just gives me the string that i wrote or maybe i joined the programs wrong. Can you add that part to your previous answer? Please, that would really be helpfull this is kinda urgent


RE: Functions to remove vowels and extra blanks - heiner55 - Nov-17-2017

Replace
x = input(...)
 
with
x=multi_lines_input()



RE: Functions to remove vowels and extra blanks - RiceGum - Nov-17-2017

Did that! Thanks! Getting this error:
Traceback (most recent call last):
File "C:\Users\Utilizador\Desktop\5.2.py", line 58, in <module>
x = eraseVowels(x)
File "C:\Users\Utilizador\Desktop\5.2.py", line 27, in eraseVowels
for car in cadeia:
TypeError: 'NoneType' object is not iterable


RE: Functions to remove vowels and extra blanks - heiner55 - Nov-17-2017

#!/usr/bin/env python3
import sys

def isVowel(s):
    if s in 'aeiou':
        return True
    else:
        return False

def eraseVowels(cadeia):
    nova_cadeia =''
    for car in cadeia:
        if isVowel(car):
            nova_cadeia += ''
        else:
            nova_cadeia += car
    return nova_cadeia

def eraseExtraBlanks(s):
    while '  ' in s:
        s=s.replace('  ',' ')
    return s.strip()

def multi_line_input():
    lines = ""
    while True:
        line = input("input: ")
        if line == '.':
            break
        else:
            lines += line + "\n"
    return lines

x = multi_line_input()
x = eraseExtraBlanks(x)
x = eraseVowels(x)
print(x)
#done



RE: Functions to remove vowels and extra blanks - RiceGum - Nov-17-2017

Thanks a lot!


RE: Functions to remove vowels and extra blanks - DeaD_EyE - Nov-17-2017

You can reduce the code.

def isVowel(s):
    if s in 'aeiou':
        return True
    else:
        return False
to

def isVowel(s):
    return s.lower() in 'aeiou'
Erasing vowels:

def eraseVowels(cadeia):
    return ''.join(char for char in cadeia if not isVowel(char))