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 15:30
Melissa needs to add a topic to an email that she will send to her teacher. choose the name of the field where she should type her topic.
Answers: 2
question
Computers and Technology, 23.06.2019 03:50
Q-1 which of the following can exist as cloud-based it resources? a. physical serverb. virtual serverc. software programd. network device
Answers: 1
question
Computers and Technology, 23.06.2019 20:40
On nba 2k 19, every time i try to join a my park game, it leads ro a website telling my dad that he needs ps plus. i already have ps plus though. how do i fix this?
Answers: 2
question
Computers and Technology, 25.06.2019 09:50
Part a: data processing given a data file, find the max, min, and average values of columns. also, create an addition column that is based on the other columns. there will be no error checking required for this lab. you are provided with a data file named (surprise! ) data.txt. data is arranged in columns where each item of data is twelve columns wide (so it is easy to extract data items using slicing): name height(m) weight(kg) joe 1.82 72.57 mary 1.60 63.50 dion 1.90 90.71 kayla 1.72 66.31 jose 1.78 70.23 sofia 1.63 65.12 erik 1.98 92.21 sara 1.57 65.77 your task is read the file data.txt and calculate the max, min, and average of the height and weight columns and to add an additional column that has the bmi calculated based on each height and weight. your output will look like this (and needs to be formatted like this). to match the testing on mimir here is the format string: "{: < 12s}{: < 12.2f}{: < 12.2f}{: < 12.2f}"
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
Mathematics, 03.02.2021 20:10
question
Mathematics, 03.02.2021 20:10
question
Mathematics, 03.02.2021 20:10
question
History, 03.02.2021 20:10
question
Spanish, 03.02.2021 20:10
Questions on the website: 13722363