Skip to content

Instantly share code, notes, and snippets.

@Caleb2501
Created July 7, 2013 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Caleb2501/5945409 to your computer and use it in GitHub Desktop.
Save Caleb2501/5945409 to your computer and use it in GitHub Desktop.
This one wasn't too hard got it to do the correct thing on the first run! woot!
# Write a program that takes a list of integers and a target number and determines if any two integers
# in the list sum to the target number. If so, return the two numbers.
# If not, return an indication that no such integers exist.
numList = []
def checkSum(numbers, sum):
for num in numbers:
for pNum in numbers:
if num + pNum == sum:
return num, pNum
print "Please enter a number: "
sumTo = input(">> ")
times = input("How many numbers would you like to list for comparison (5 to 50)? ")
if times > 50 or times < 5:
print "That isn't a good number, how about a list of 10 numbers"
times = 10
while times > 0:
times -= 1
print "Enter a number %d more to go: " %( times)
newNumber = input(">> ")
numList.append(newNumber)
num1, num2 = checkSum(numList, sumTo)
print "%d and %d are two numbers in your list that when added together become the specified sum %d." %(num1, num2, sumTo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment