Answer to Question #291326 in Python for Sky

Question #291326

part 2:


The function should return the number of winners (i.e., the number of participants whose lucky draw number is a multiple of factor-digit and contain the must-have-digit).


Your advised to write a helper function contain_digit(number, digit) that returns True if number contains digit, or False otherwise. Example, function call contain_digit(15, 5) returns True. This function will be called by the find_winners(factor, must_have, n) function to check existence of must_have digit.


1
Expert's answer
2022-01-27T12:34:59-0500
# Python 3.9.5

def contain_digit(number, digit):
    for i in str(number):
        if int(i) == digit:
            return True
    return False


def find_winners(factor, must_have, number):
    if must_have == True and number % factor == 0:
        print('We have one winner')
    else:
        print('We don\'t have winner')


def main():
    number = 18
    digit = 5
    factor = 3
    must_have = contain_digit(number, digit)
    find_winners(factor, must_have, number)


if __name__ == '__main__':
    main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS