Python文字列を入力し、文字列の単語の個数を出力します


str = input("         :")
str1 = str.strip() #          
index = 0
count = 0
while index < len(str1):
    while str1[index] != " ": #       ,   1
        index += 1
        if index == len(str1): #                     
            break
    count += 1  #      1
    if index == len(str1): #                     
        break
    while str1[index] == " ": #        ,   1,            
        index += 1
print("          count = %d   " % count)