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
This is my code below
occupied_spaces [1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0]We have been told we are not aloud to use the "sum" command.
This is my code below
#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')i only seem to get 0% back. is there something i am missing? looking for some hints, i probs just missing one small thing.