The first two lines are a complete story by themselves:
" The last man on Earth sat alone in a room. There was a knock on the door..."
The Zan have killed off all life on Earth other than pairs of specimens for their zoo of exotic Earth fauna. Walter Phelan is the last man on Earth, but Grace Evans, the last woman, is not overly impressed with him and maintains her distance.
The Zan, who are ageless, become disturbed when, one by one, the other animals begin to die. They turn to Walter for advice. He tells them that the creatures have perished from lack of affection, suggesting that they pet the survivors regularly to keep them alive. He demonstrates with one of them. When the Zan begin to die, they depart the planet in fear. It is then revealed that the creature Walter advised them to pet was a poisonous snake.
Then Walter discusses the future of the human race with Grace. She is shocked by his proposal and leaves as he intended to use the Zan technology left behind to create "the master race". The narrative then ends as it began:
"The last man on Earth sat alone in a room. There was a knock on the door..."

Question: How do the Zan learn how to show affection to the animals?
Answer: Walter demonstrates for them
Alternative answer: Walter shows them how to pet the animals