Created
July 17, 2019 08:47
-
-
Save jatinsharrma/9a4762b2db4bca2f69d6e99c7c613e4f to your computer and use it in GitHub Desktop.
count of pairs of numbers in the list that adds up to n
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Write a python function, which accepts a list of positive integers with no repetitions and returns count of pairs of numbers in the list that adds up to n. The function should return 0, if no such pairs are found in the list. | |
def find_pairs_of_numbers(num_list,n): | |
count = 0 | |
for num1 in num_list: | |
for num2 in num_list: | |
if (num1 + num2) == n: | |
count = count + 1 | |
return int(count/2) | |
num_list=[1, 2, 7, 4, 5, 6, 0, 3] | |
n=9 | |
print(find_pairs_of_numbers(num_list,n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment