Trying to count words in a string

后端 未结 7 792
醉话见心
醉话见心 2021-02-06 03:28

I\'m trying to analyze the contents of a string. If it has a punctuation mixed in the word I want to replace them with spaces.

For example, If Johnny.Appleseed!is:a*good

相关标签:
7条回答
  • 2021-02-06 04:06
    #Write a python script to count words in a given string.
     s=str(input("Enter a string: "))
     words=s.split()
     count=0
      for word in words:
          count+=1
    
      print(f"total number of words in the string is : {count}")
    
    0 讨论(0)
提交回复
热议问题