defcount_str(strs): int_count,str_count,spa_count,other_count = 0,0,0,0
for i in strs: # 遍歷字串
if i.isdigit(): # 判斷是否為數字
int_count += 1
elif i.isalnum(): # 判斷是否為字母
str_count += 1
elif i.isspace(): # 判斷是否為空格
spa_count += 1
else:
other_count +=1
print("字串s中,數字個數={},字母個數={},空格個數={},其他個數={}".format(int_count,str_count,spa_count,other_count))
if __name__ == "__main__":
strs = input("請輸入字串s:")
count_str(strs)
defcount_str(strs): int_count,str_count,spa_count,other_count = 0,0,0,0
for i in strs: # 遍歷字串
if i.isdigit(): # 判斷是否為數字
int_count += 1
elif i.isalnum(): # 判斷是否為字母
str_count += 1
elif i.isspace(): # 判斷是否為空格
spa_count += 1
else:
other_count +=1
print("字串s中,數字個數={},字母個數={},空格個數={},其他個數={}".format(int_count,str_count,spa_count,other_count))
if __name__ == "__main__":
strs = input("請輸入字串s:")
count_str(strs)