Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

FOR PYTHON: A common kind of puzzle question is how many numbers between 1 and 10000 contain the digit 9?. Write a function howManyNumsWithDigit(maxNumber, digit)

FOR PYTHON: A common kind of puzzle question is "how many numbers between 1 and 10000 contain the digit 9?". Write a function howManyNumsWithDigit(maxNumber, digit) that returns the number of numbers from 1 through maxNumber that contain the given digit.

For example howManyNumsWithDigit(10, 5) should return 1, howManyNumsWithDigit(10,1) should return 2, and howManyNumsWithDigit(40, 2) should return 13. Your function must use a list comprehension (but remember, it returns a number not a list!) and have only one line of code (in addition to the def line).

Note: of course, there are ways to solve this problem that don't use list comprehensions. But, for this assignment, you must use a list comprehension. Use a list comprehension to create a list of all the numbers that contain the digit, and then simply return the length of that list.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Describe the purpose of disability insurance programs. lop85

Answered: 1 week ago

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago