can someone repair my code because it ends after it deletes the first dict.
The function should delete all dictionaries which value of density is lower than 5.500
Expected output would be:
[{'name': 'Earth', 'Density': 5.513}]
Mine is:
[{'name': 'Earth', 'Density': 5.513},
{'name': 'Venus', 'Density': 5.204}]`
My code:
base = [
{"name": "Mars", "Density": 5.427},
{"name": "Earth", "Density": 5.513},
{"name": "Venus", "Density": 5.204},
]
density = float(input("density? "))
def deletePlanet(density, base):
for index in range(0, len(base)):
while base[index]["Density"] < density:
del base[index]
return base
print(deletePlanet(density, base))