- 1

Counterpart

For a number n, we shall define it's k counterpart as the amount needed to be added to n to make it equal to k. For example, For 2, the 5 counterpart is 3 For 2, the 10 counterpart is 8 For 27, the 12 counterpart is -15 Complete the given method solve which takes as parameter a list A and a number k. You have to find out whether the the first element's k counterpart exists in the rest of the list. If yes, print Exists. Otherwise, print Doesn't Exist Example Input: 10 24 91 8 7 3 13 Output: Exists Explanation: 10's 13 counterpart is 3, which exists in the list

17th Oct 2021, 7:54 AM
Gopi Satya Sivakumar
Gopi Satya Sivakumar - avatar
2 Answers
+ 1
list1 = input().split() cpart = int(input()) needed = cpart - int(list1[0]) if str(needed) in list1: print("Exists") else: print("Does not Exist.")
17th Oct 2021, 3:54 PM
Co.De
Co.De - avatar
- 1
def counterPart(alist,num): result="Doesn't Exist" for n in alist: if (n-num) in alist: result="Exists" break print(result) counterPart([24,91,8,7,3,13],10)
17th Oct 2021, 10:21 AM
Jasy Fabiano
Jasy Fabiano - avatar