Created
July 7, 2013 23:50
-
-
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!
This file contains 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 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