Python question

Asked 2 years ago, Updated 2 years ago, 18 views

How can I write a program that counts the number of characters in a string?

python

2022-09-22 19:19

1 Answers

Hi, how are you?

Why don't you simply use 'Ga' < c < 'He' when you look for Korean?

word = 'ABs%1C clear nifera$'

upper_counter = 0
lower_counter = 0
number_counter = 0
hangul_counter = 0
etc_counter = 0

for c in word:

    if c.isupper():
        upper_counter += 1
    elif c.islower():
        lower_counter += 1
    elif c.isdigit():
        number_counter += 1
    elif 'Ga' < c< 'Hehe': # If you want to process consonants, compare 'a' <c< 'hh' like this
        hangul_counter += 1
    else:
        etc_counter += 1


print(f'upper_counter: {upper_counter} lower_counter: {lower_counter} number_counter: {number_counter} hangul_counter: {hangul_counter} etc_counter: {etc_counter}')

Have a nice day


2022-09-22 19:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.