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 variable name must start with a letter or the underscore character. • A variable name cannot start with a number. • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) • 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: 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. Eurthermore Python keywords will be considered to be Python names
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 variable name must start with a letter or the underscore character. • A variable name cannot start with a number. • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) • 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: 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. Eurthermore Python keywords will be considered to be Python names
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
![7.12 Word Count Python Sytle
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 variable name must start with a letter or the underscore character.
• A variable name cannot start with a number.
• A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _)
• 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.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fda859fed-ae51-422c-9773-627805a70b82%2Fbbf8f3db-8d4c-4064-86a0-47683867fd52%2F9moe21_processed.png&w=3840&q=75)
Transcribed Image Text:7.12 Word Count Python Sytle
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 variable name must start with a letter or the underscore character.
• A variable name cannot start with a number.
• A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _)
• 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.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education