zerodivision我下面的代碼在為空時(shí)返回錯(cuò)誤occupied_spaces。occupied_spaces = [ ]cars = occupied_spaces.count(1)spaces = occupied_spaces.count(0)if not occupied_spaces: print('The list is empty') percentage = cars/len(occupied_spaces) * 100print(percentage, '%')有人可以解釋為什么會(huì)這樣嗎?
'If not' 以避免零除法
慕尼黑5688855
2023-02-12 19:01:07