Question: mulDigits ( num , fn ) ( 1 pt ) Returns the multiplication of all digits in num for which fn returns True when receiving

mulDigits(num, fn)(1 pt)
Returns the multiplication of all digits in num for which fn returns True when receiving the digits
as argument. You can assume that fn will always be a function that takes one number as argument
and returns a boolean value. You are not allowed to use lists, tuples, strings or convert num to
string using str(num).
Examples:
>>> isTwo = lambda num: num ==2 # Simple anonymous function
>>> mulDigits(5724892472, isTwo) # Only 2 evaluates to True
8
>>> def divByFour(num): # Conventional function definition
... return not num%4
>>> mulDigits(5724892472, divByFour) # Only 4 and 8 evaluate to True
128
getCount(x)(1 pt)
Takes in a positive integer and returns a function that takes in an integer num, returning how many
times x appears as a digit in num. You are not allowed to use lists, tuples, strings or convert num
to string using str(num). Note that num//10 does not behave the same when num is negative,
562//10 returns 56 while -562//10 returns -57.
Examples:
>>> digit = getCount(7)
>>> digit(945784578457077076)
6
>>> getCount(6)(-65062156)
3
Dual_Iterator (3 pts)
An iterator that can iterate through all the elements of some sequence (list, string), and when
reaching the end of the sequence, it loops back to the beginning. The iterator also includes the
method reverse() that allows us to traverse in the reverse order, so when we reach the first element
of the sequence, it should loop to the last element of the iterable. You will need to initialize the
iterator settings in the constructor of the Dual_Iterator class. You are not allowed to use any built-
in reverse methods such as reverse(),[::-1], etc.
The implementation of the __iter__ method has been provided in the starter code. Do not modify
it. You should only implement the following methods:
__init__ method: iterator settings. Takes a sequence as argument. In lecture 9.3 and 9.31,
we presented examples of iterator implementations. Revise those examples so you can
determine any additional settings besides the sequence (our solution uses only 2 more
attributes)
__next__: returns the next value. It does not raise a StopIteration exception since this is an
infinite iterator (loops back)
reverse(): Takes no arguments and enables the change of direction in the iterator: from
forwards to backwards and vice versa
Examples:
>>> it = Dual_Iterator([2,4,6,8,10])
>>> next(it)
2
>>> next(it)
4
>>> next(it)
6
>>> it.reverse() # it stopped at 6, change direction
>>> next(it)
4
>>> next(it)
2
>>> next(it)
10
>>> it.reverse() # it stopped at 10, change direction
>>> next(it)
2
>>> next(it)
4
>>> next(it)
6
>>> it.reverse() # it stopped at 6, change direction
>>> next(it)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!