I'm trying to write a program which asks for the number of animals and then the name and the population of each animal. I want to get it to add the population of each animal but I having trouble getting the variables from the dictionary and adding them.

This is what I have so far.

animals={}
x=input("How many animals?")
loop=0
while loop!=x:
    animal=raw_input("What is the animal called?")
    popul=input("what is the population?")
    animals[animal]=popul
    loop=loop+1
print "the total number of animals is"
print "the total number of animals is", sum(animals.values())
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.