Jun-15-2020, 10:44 AM
Hi everyone, i very new to python, for my uni course they have tasked us on finding a percentage in a list of 1's and 0's. for example
We have been told we are not aloud to use the "sum" command.
This is my code below
i only seem to get 0% back. is there something i am missing? looking for some hints, i probs just missing one small thing.
1 |
occupied_spaces [ 1 , 1 , 0 , 0 , 0 , 1 , 1 , 0 , 0 , 1 , 0 ] |
This is my code below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#Car Park Q2 #List of occupied spaces occupied_spaces = [ 1 , 0 , 1 , 1 , 0 , 0 , 0 , 1 , 1 , 1 , 0 ] #Length of list length = 0 for parked in occupied_spaces: length = length + 1 #Variables parked = ( 1 ) empty = ( 0 ) #Percentage percentage = int (parked / len (occupied_spaces)) * 100 print (percentage, '% of spaces are occupied' ) |