I am coding something were you enter a main number, then a list of numbers again. It is supposed to see if any two numbers in the list add up the the main number. I am using for() loops to compare the numbers, but they don't seem to be running.
IsDone = None
AddingList = []
MainNum = input('Enter a number: ')
Cnt = 0
while IsDone != 'yes':
NewItem = int(input('Enter a number: '))
AddingList.append(NewItem)
IsDone = input('Are you done yet? ')
for i in range(len(AddingList)):
for a in range(len(AddingList)):
if int(AddingList[i]) + int(AddingList[a]) == MainNum:
print(AddingList[i])
print(AddingList[a])
I am coding something were you enter a main number, then a list of numbers again. It is supposed to see if any two numbers in the list add up the the main number. I am using for() loops to compare the numbers, but they don't seem to be running.
IsDone = None
AddingList = []
MainNum = input('Enter a number: ')
Cnt = 0
while IsDone != 'yes':
NewItem = int(input('Enter a number: '))
AddingList.append(NewItem)
IsDone = input('Are you done yet? ')
for i in range(len(AddingList)):
for a in range(len(AddingList)):
if int(AddingList[i]) + int(AddingList[a]) == MainNum:
print(AddingList[i])
print(AddingList[a])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.