I've recently started learning python and I have an assignment which I need help with.

Write python code to check if there exist two elements in the array whose sum is equal to the sum of the entire array Jun 17, 2019 in Python 164 views
Hahah! Its an assignment and you should do it by yourself. I can help with working around the logic.
Hahah! Help me out with the logic. That'd be good enough.

## 2 answers to this question.

You can find the sun of the array. Then for each element in the array a[i], look for a value that is equal to sum - a[i]. answered Jun 17, 2019 by Viky

You can try something like this Harsh:

```def checkPair(a, n):
s = set()
sum = 0
# Find sum of whole array
for i in range(n):
sum += a[i]
# / If sum of array is not
# even than we can not
# divide it into two part
if sum % 2 != 0:
return False
sum = sum / 2
# For each element arr[i], see if
# there is another element with
# value sum - arr[i]
for i in range(n):
val = sum - a[i]
if a[i] not in s:
# If element exist than
# return the pair
if val in s:
print("Pair elements are",
a[i], "and", int(val))
# Driver Code
a = [2, 11, 5, 1, 4, 7]
n = len(a)
if checkPair(a, n) == False:
print("No pair found")
``` answered Jun 17, 2019 by Ayman

## What is the logic to check if a number is prime or not in python?

I am looking for a function with ...READ MORE

+1 vote

## how do I check the length of an array in a python program?

lets say we have a list mylist = ...READ MORE

+1 vote

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

## how do i use the enumerate function inside a list?

can you give an example using a ...READ MORE

## Lowercase in Python

You can simply the built-in function in ...READ MORE