check whether items in a list add to a certain value PYTHON 3

Watch this thread
EmergencyBagels
Badges: 18
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#1
Report Thread starter 5 years ago
#1
hey,

just wondering if anyone has any idea of the best way to check whether any pair of items in a list of numbers in python add to a certain number.

id post my code that i have done so far here but am a bit worried about that getting me in trouble somehow, i dunno, its for uni coursework.


essentially at the moment i have a for loop in a for loop

the first for loop takes the value for list[0], the second then iterates over the rest of the list to check whether any of the numbers add with list[0] to a specific number. . then once that is done we go onto list[1] and do the same again etc.


this is horribly messy and confusing although perhaps thats just my lack of skill at writing clear and concise code

it also isnt very effective... if the pair add to a number, i want to change both of the items. but then i would have to check the list again from the beginning! im not sure if i can start the for loop again this way, and again, it just feels really silly and inefficient.

thank you, and sorry if this isnt very clear. if you want more clarification i can try post bits of my work i suppose but its a mess
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest

Were exams easier or harder than you expected?

Easier (37)
26.43%
As I expected (46)
32.86%
Harder (50)
35.71%
Something else (tell us in the thread) (7)
5%

Watched Threads

View All