Skip to content

Commit 1ed3330

Browse files
committed
day 054 - person class BMI
1 parent 5a17ba2 commit 1ed3330

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

054/person_class.py

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

LOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
| 051 | May 19, 2017 | [Use #Python #requests module on a page behind a login](051) | Wrote a quick script to pull web page data from a page behind a login. In this example I pull my post data from freecycle.org. Will write a detailed post about it this week. |
5656
| 052 | May 20, 2017 | [Build a user focused REPL with prompt_toolkit (source @amjithr)](052) | Code from PyCon2017 [Awesome Commandline tools session](https://speakerdeck.com/amjith/awesome-commandline-tools) |
5757
| 053 | May 21, 2017 | [Script to start automating posting to our PyBites FB group](053) | Also 'a' possible solution for challenge 19 of this week |
58-
| 054 | May 22, 2017 | [TITLE](054) | LEARNING |
58+
| 054 | May 22, 2017 | [Script to create a person #class and calculate BMI](054) | A simple script to demo basic Python Classes. It calculates the BMI of an individual |
5959
| 055 | May 23, 2017 | [TITLE](055) | LEARNING |
6060
| 056 | May 24, 2017 | [TITLE](056) | LEARNING |
6161
| 057 | May 25, 2017 | [TITLE](057) | LEARNING |

0 commit comments

Comments
 (0)