10) c. Creating an Instance of a Class Examples




Ward is a biologist interested in doing some analysis on the animals of the earth. For this reason he has created a class named Animal which has an animal name, no. of eyes and no. of limbs as the attribute names. Create an instance of this class to be used for further analysis.

1
2
3
Output:
Creating an instance of Animal
Animal instance is created




Joel is a mathematics professor at Neverland Institute and is creating some simulations on Complex Numbers. For a complex number to work he needs both the real and imaginary part of the complex number. Create a program that creates an instance of complex numbers and prints the instance in a+ib format where a is the real number and i is the imaginary part.

1
2
3
4
5
6
Output:
Enter the real part of the number
 5
Enter the imaginary part of the number
 10
The real number is 5 + i10




Neverland was always known as a hunting playground but with a lot of tourist hunters there is a fear of some species becoming extinct. The government has come up with a way to tackle this problem. According to them no tourist should be able to hunt. For this reason they have created a hunters database in which a person has to add himself if he wants to hunt. Each hunter is denoted by a name, nationality and skill. Please create a Hunter class that the government could use.

1
2
3
4
5
6
7
8
9
Output:
Enter the hunter details
Name?
 Abe Lincoln Vampire Hunter
Nationality?
 American
Skill?
 Killing vampires
Hunter instance is created




Ziknas is a game developer and wants to create a 2 player game to play with his girlfriend. He has the basic layout with him and wants to try it by creating 2 dummy players. Each player is denoted by health and name. Please create 2 instances of this Player class that can be used further by Ziknas to impress his girlfriend.

1
2
3
Output:
Creating player 1 and player 2
Instances of players created




Kimer is Head of the Department of Neverland Institute and manages the computer department. He wants to send a list of student names for a recommendation but the system expects the names to be in a specific format. For this he has created a Student class. He will send a list of instances of this class to the external system. Can you write the code for this? The student class is already created. Create a list with 3 student instances which can be further used downstream.

1
2
Output:
Creating 3 instances




Kungus is a demon plotting a scheme to defeat god Dryllus. Before Kungus attacks the god he wants to make sure that the army is in the best of health. He has an army class that has 4 instances: North, South, East, West. Whenever he prints an instance of army class, all that is displayed is gibberish. He wants to take care of them. Please help him do so. (Hint: repr or str can help in this task).

1
2
Output:
The area is North total population of army is 12166 and the health is 100000