Technology Sharing

Huawei HJ40 character counting test

2024-07-08

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Huawei HJ40 character counting test

topic:

insert image description here

idea:

Count the number of the four characters in the above question and store them in a dictionary, and output them in the specified order

input_str = input()

str_dict = {"alpha": 0, "space": 0, "number": 0, "others": 0}

for i in input_str:
    if i.isalpha():
        str_dict["alpha"]  = 1
    elif i == " ":
        str_dict["space"]  = 1
    elif i.isdigit():
        str_dict["number"]  = 1
    else:
        str_dict["others"]  = 1

print(str_dict["alpha"])
print(str_dict["space"])
print(str_dict["number"])
print(str_dict["others"])