I’m trying to make something to let you choose a bot’s WPM in a type racing game so let’s say you have a sentence like
JavaScript
x
2
1
for car owners, transmission failure can be a complete nightmare, costing thousands of dollars to fix or replace.
2
I need to find out how many words there are in it and the words can include periods and comma’s like
JavaScript
1
2
1
for,
2
the comma can be included in the one word so that is just one word. And I need it to be able to read this sentence from a .txt file and give me the word count so I can calculate the delay needed to get the desired WPM. I have no idea how to do that so any help would be appreciated.
Advertisement
Answer
As mentioned in a comment by @S3DEV:
Once you have read the text file into a string s
, you can do len(s.split())
to find the amount of words!