subject

We are familiar with word count features of word processors such as found in MS-Word. These will report the number of words and characters in a document. We would like to write a function that we can eventually use to analyze a python program. That is write a function that will return the number of non-white space characters, the number of variable/function names used in the program, and the number of characters used in the variable/function names. The rules for Python names are:
A. A variable name must start with a letter or the underscore character.
B. A variable name cannot start with a number.
C. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
D. Variable names are case-sensitive (age, Age and AGE are three different variables)
Write a function python_word_count which when passed a string containing python code will return a tuple of total number of non-white space characters, number of characters found in the Python names, and the number of Python names found in the string. Write a main that will input a string and print the values returned by python_word_count together with the average length of the Python words. Ex:
def python_word_count(text):
Count of Python names: 3
Count of characters in Python names: 24
Average length of Python names: 8.0
Count of characters: 27
Ex 2:
if user_year % 4 == 0 and (user_year % _CENTURY != 0 or user_year % 400 == 0):
Count of Python names: 7
Count of characters in Python names: 42
Average length of Python names: 6.0
Count of characters: 61
Note: For simplicity, we will ignore the the fact that names within strings or in comments are not really Python names. Thus words inside quotes or in a comment will be counted as Python names. For consideration; what would be needed to exclude such words being counted.
Furthermore Python keywords will be considered to be Python names.
All in Python please =)

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 10:30
You have a large, late-model pick-up truck with a rear seat. the pick-up truck weighs 6,500 pounds. the florida seat belt law
Answers: 1
question
Computers and Technology, 23.06.2019 04:10
2pointswho was mikhail gorbachev? oa. a russian leader who opposed a coupob. a polish leader who founded the labor union "solidarityoc. a soviet leader who called for a closer relationship with the unitedstates, economic reform, and a more open societyd. a soviet leader who called for more oppression in the soviet union
Answers: 3
question
Computers and Technology, 23.06.2019 17:00
1. which of the following is not an example of an objective question? a. multiple choice. b. essay. c. true/false. d. matching 2. why is it important to recognize the key word in the essay question? a. it will provide the answer to the essay. b. it will show you a friend's answer. c. it will provide you time to look for the answer. d. it will guide you on which kind of answer is required.
Answers: 1
question
Computers and Technology, 24.06.2019 01:00
Mastercard managers are motivated to increase (1) the number of individuals who have and use a mastercard credit card, (2) the number of banks and other clents who issue mastercards to customers and/or employees, and (3) the number of locations that accept mastercard payments. discuss how mastercard could use its data warehouse to it expand each of these customer bases.
Answers: 3
You know the right answer?
We are familiar with word count features of word processors such as found in MS-Word. These will rep...
Questions
question
Social Studies, 16.02.2021 17:40
question
Mathematics, 16.02.2021 17:40
question
Mathematics, 16.02.2021 17:40
question
Mathematics, 16.02.2021 17:40
Questions on the website: 13722367