- 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
2 Respostas
+ 1
list1 = input().split()
cpart = int(input())
needed = cpart - int(list1[0])
if str(needed) in list1:
print("Exists")
else:
print("Does not Exist.")
- 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)