Skip to content

Commit

Permalink
day 054 - person class BMI
Browse files Browse the repository at this point in the history
  • Loading branch information
hobojoe1848 committed May 23, 2017
1 parent 5a17ba2 commit 1ed3330
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions 054/person_class.py
@@ -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()))
2 changes: 1 addition & 1 deletion LOG.md
Expand Up @@ -55,7 +55,7 @@
| 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. |
| 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) |
| 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 |
| 054 | May 22, 2017 | [TITLE](054) | LEARNING |
| 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 |
| 055 | May 23, 2017 | [TITLE](055) | LEARNING |
| 056 | May 24, 2017 | [TITLE](056) | LEARNING |
| 057 | May 25, 2017 | [TITLE](057) | LEARNING |
Expand Down

0 comments on commit 1ed3330

Please sign in to comment.