[Python] making pure string from a sentence [closed]

Discussão em 'Python' iniciado por Stack, Fevereiro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I want get a sentence from user and then convert to pure string. delete all spaces, signs and number. I want to count the vowel alphabets and consonants alphabets. actually i want censor the numbers and spaces and signs to have just alphabet then count how many of alphabets are vowel(how many are in the vowel list)

    import re
    sentence = input("Enter your sentence : ")
    def vowel_checer(sentece):
    vowels_list = ["a","e","o","y","u","i"]
    char_list = [",",".","(",")","!","?"]
    num_list = ["0","1","2","3","4","5","6","7","8","9"]
    sentece = sentece.replace(" ","")
    sentece = re.sub(char_list,"",sentece)
    sentece = re.sub(num_list,"",sentece)
    vowel_count = 0
    consonants_count = 0
    if sentece.isalpha():
    for char in sentece:

    if char in vowels_list:
    vowel_count += 1
    else:
    consonants_count = len(sentece) - vowel_count
    return vowel_count , consonants_count
    resoult = vowel_checer(sentence)
    print(resoult)

    Continue reading...

Compartilhe esta Página