Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started