how to create 12 people identites that could be male or female with their own weight, height and gender
Question:
The question wants me to create 12 persons on python these 12 people can be males, females randomly generated with their own height weight and gender all taken randomly, then to find the average weight of the males. I’m not sure how I can create the people.
Answers:
Well you’ll probably gonna use classes for this task :
What is OOP
OOP focuses on the objects that are
required to be manipulated instead of logic.
- It makes development and maintenance easier
- It provides data hiding
- It provides ability to simulate real-world
- less memory and organized
- reusable
Here’s an example on how you can achieve this using classes in python
class Person:
# class constructor
def __init__(self, age, gender, height, weight):
self.height = height
self.width = width
self.age = age
self.gender = gender
person1 = Person(18, "Male", 5, 20)
print(person1.height)
The question wants me to create 12 persons on python these 12 people can be males, females randomly generated with their own height weight and gender all taken randomly, then to find the average weight of the males. I’m not sure how I can create the people.
Well you’ll probably gonna use classes for this task :
What is OOP
OOP focuses on the objects that are
required to be manipulated instead of logic.
- It makes development and maintenance easier
- It provides data hiding
- It provides ability to simulate real-world
- less memory and organized
- reusable
Here’s an example on how you can achieve this using classes in python
class Person:
# class constructor
def __init__(self, age, gender, height, weight):
self.height = height
self.width = width
self.age = age
self.gender = gender
person1 = Person(18, "Male", 5, 20)
print(person1.height)