if user_year % 4 = 0 and (user_year % _CENTURY != 0 or user_year % 400 == 0): =D3= Count of Python names: 7 Count of characters in Python names: 42 Average length of Python names: 6.0 Count of characters: 61

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
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
Transcribed Image Text: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
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY