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.
# 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()
Comments
Leave a comment