Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a17ba2
commit 1ed3330
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters