Demo entry 6036595

TASK 4 HOMEWORK

   

Submitted by ISMAEL BENMADANI on Sep 20, 2016 at 15:35
Language: Python. Code size: 1.4 kB.

def inputCountries():
   localCountryList = []
   for country in range (0,5)  : #repeat this 5 times
       nameCountry = input("Input the name of the country:")
       popCountry = int(input("Write thE population of the country(in millions):"))
       areaCountry = int(input("Write the area of the country:"))
       densityCountry = 0.0
       currentCountry =[nameCountry,popCountry,areaCountry,densityCountry]
       CountryList.append(currentCountry)
   return (CountryList)

def calculateAvaragePop(inList):
    totalPop = 0
    for i in inList :
        currentPop = int([1])
        totalPop += currentPop
    avaragePop = totalPop/5
    return (avaragePop)

def setDensity(inList):
  newList = inList [:]
  currentDensity = 0
  for i in newList :
      currentPop = i[1]
      currentArea = i[2]
      currentDensity = (currentPop*1000.0)/currentArea
      i[3] = currentDensity
  return(newList)

def calculateMaxDensity(inList):
  macDeansity = 0.0
  for i in inList :
     if i[3] > maxDensity :
        maxDensity = i[3]
  return(maxDensity)                    

myList = inputCountries()
avaragePopulation = calcAvaragePop (myList)
myList = setDensityInList(myList)
maxDensity = calcMaxDensity(myList)
print("Avarage population = ",str(avaragePopulation),"million people")
print("max density = ",str(maxDensity),"people per km2")

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).