I have been given a problem where - whenever the user types the number '6' in the digits (it can be anywhere in the digit's place), he has to type or generate, a combination of two values that add up to the entered number.
Ex1 : if I input number "16" ==> (7,9) or (8,8) or (1,15) etc., but not (0,16) or (6,10) etc.,
Ex2 : if I input number "61" ==> (58,3) or (59,2) or (57,4) etc., but not (0,61) or (60,1) etc.,
Ex3 : if I input number "168" ==> (75,93) or (80,88) or (10,158) etc., but not (168,0) or (60,108) etc.,
I tried to work around this problem and got :
'''
def faulty_num():
x=str(input())
result=[]
for i in range(1, int(x)+1):
for j in range(1, int(x)+1):
if (i+j == int(x) and int(x)%10==6):
result.append((i,j))
print(*result[:(int(x)//2)])
'''
when I input 16 ==> (1, 15) (2, 14) (3, 13) (4, 12) (5, 11) (6, 10) (7, 9) (8, 8)
Kindly forgive me, if my code is messy.
In the code above, I can eliminate combinations having 6 by mentioning (i!=6 ,j!=6) or (i%10==6 , j%10==6) in my "if condition". I won't be able to do that when, the digit's size increases. In the mentioned code block, this if condition =
if (i+j == int(x) and int(x)%10==6):
will only generate the required combinations, when the ones place of the digit is "6" and only generate combinations that have the digit 6. The code only gets more convoluted, the more I think. But, I am honestly clueless at this point. Any suggestion will definitely be helpful. Thank you for your valuable time!