-
Notifications
You must be signed in to change notification settings - Fork 168
/
Copy pathperson_class.py
32 lines (24 loc) · 1.01 KB
/
person_class.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!python3
#Quick example script to create a person based class.
class Person(object):
def __init__(self, name, age, height, weight, gender, job):
self.name = name
self.age = age
self.height = height
self.weight = weight
self.gender = gender
self.job = job
#Manual way of displaying job to demo a class function
def get_job(self):
return self.job
#Calculate BMI (Body Mass Index) = weight * height (in metres squared)
def bmi(self):
return (self.weight / ((self.height / 100) ** 2))
#Creating some awesome people using the class
bob = Person("Bob", 30, 180, 80, "Male", "Professional Awesome Programmer Guy")
julian = Person("Julian", 30, 170, 70, "Male", "Professional Smack Talker")
#Technically could have pulled job info with just .job
print(bob.name + ": " + bob.get_job())
print(julian.name + ": " + julian.get_job())
#Calculating BMI using Replacement Field String formatting
print("{} BMI: {}".format(julian.name, julian.bmi()))