I have two lists of booleans buy_machine and broken_machine. I want to make a third list working_machines that sums the number of machines bought and subtracts the number of broken machines.
I tried the following code and the resulting list is full of 'nothing' I expected at least to see the 'plus 1' or 'minus 1', this was just to try something, I have no idea how to actually make the working_machines list to sum or subtract the booleans
years = list(range(1, 21))
buy_machine = []
broken_machine = []
working_machines = []
for year in years:
if year <= 5:
buy_machine.append(True)
else:
buy_machine.append(False)
if 10 % year == 10 and year <= 15:
broken_machine.append(True)
else:
broken_machine.append(False)
if buy_machine == True and broken_machine == False:
working_machines.append('plus 1')
elif buy_machine == False and broken_machine == True:
working_machines.append('minus 1')
else:
working_machines.append('nothing')
buy_machine
[True,
True,
True,
True,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False]
broken_machine
[False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
True,
True,
True,
True,
False,
False,
False,
False,
False]
working_machines
['nothing',
'nothing',
'nothing',
'nothing',
'nothing',
'nothing',
'nothing',
'nothing',
'nothing',
'nothing',
'nothing',
'nothing',
'nothing',
'nothing',
'nothing',
'nothing',
'nothing',
'nothing',
'nothing',
'nothing']
Wanted output
working_machines
[1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0]