Beginner coder here! I am looking to make a loop that will check the list named "budget" to see if its negative, and if it is, it will use the "years" list to add the year to the list named "nodef". My end result is to have the list "nodef" to contain all the years that have no deficits.
budget = [-1075,1225,4239,6084,1489,4031,1846,600,-6409,-19262,-14011,-12969,-9220,-10453,-10315,-3500,-1500,600,600,900]
years = [2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019]
nodef = []
i = 0
if i <21:
if budget[i]<0:
nodef.append(years[i])
i += 1
else:
print(nodef)
This is what I have at the moment. Please let me know how I can approve upon this. This is purely for my own curiosity.