Advertisement
elenaD

5 part

Feb 18th, 2025
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | Software | 0 0
  1. def add_city_data(country, city, population, area):
  2.     data = load_data()
  3.     density = round(population / area, 2)
  4.     if area
  5.     else 0  
  6.     city_data = {"Core City": city, "Population": population, "Area": area, "Density": density}
  7.  
  8.     if country not in data:
  9.         data[country] = []  
  10.     data[country].append(city_data)  
  11.  
  12.     save_data(data)  
  13.     print(f"Data for {city}, {country} added successfully.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement