Computers and Technology

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 =)

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 02:30, rodfam13716
If you turn on the lock alpha button , what happens
Answers: 1
image
Computers and Technology, 22.06.2019 13:30, 21megoplin
In which phase does software coding and testing happen in the spiral model? the spiral model does not have a separate testing phase. both, software coding and testing occurs during the phase.
Answers: 3
image
Computers and Technology, 22.06.2019 23:30, Molly05
In my email i got a message it says a quick message and in message details on who its from its says nicole and under nicole is 50e0bf08e5b671@ualwgypg91wa5wl. uzo9kbud3qjwddygd5.vng -
Answers: 1
image
Computers and Technology, 22.06.2019 23:30, keviongardner
The next button in the review section shows the next available comment. next slide with no comment. previous comment. edited comment.
Answers: 1
Do you know the correct answer?
We are familiar with word count features of word processors such as found in MS-Word. These will rep...

Questions in other subjects:

Konu
Chemistry, 11.02.2022 06:30
Konu
Mathematics, 11.02.2022 06:30
Konu
Chemistry, 11.02.2022 06:30