mardi 3 novembre 2020

Trying to use a loop to take out certain character

for index in range(0,len(user_input)):
            if user_input[index] == ('-'):
                if (user_input[index - 1].isalpha() and user_input[index + 1].isalpha()):
                           target += user_input[index]
                else:
                    target =+ ' ' 
            elif user_input[index] == ("'"):
                if (user_input[index - 1].isalpha() and user_input[index + 1].isalpha()):
                           target += user_input[index]
                else:
                    target =+ ' ' 
    target = ''.join(target)
    
    target = target.split()

print(target)

Trying to have it take out certain characters I.E !#$% and keep - ' but when I print the statement its not displaying the input

Aucun commentaire:

Enregistrer un commentaire