Dec-06-2018, 02:29 PM
Hi,
I'm teaching myself Python and am having trouble with Classes and Objects.
Please see below my Python Code.
I'm struggling to figure out how to create a weight1 field that gives weight in Kgs.
Two specific questions:
1) How do I create the weight1 field?
2) Why does the invocation of age have "age()"?
thanks in advance
PC
I'm teaching myself Python and am having trouble with Classes and Objects.
Please see below my Python Code.
I'm struggling to figure out how to create a weight1 field that gives weight in Kgs.
Two specific questions:
1) How do I create the weight1 field?
2) Why does the invocation of age have "age()"?
thanks in advance
PC
# Create an object to compute John's weight in Kgs as well as age in years class User: def __init__(self, full_name, weight, birthday): self.name = full_name self.weight = weight self.birthday = birthday def age(self): today = datetime.date(2018, 12, 5) yyyy = int(self.birthday[0:4]) mm = int(self.birthday[4:6]) dd = int(self.birthday[6:8]) dob = datetime.date(yyyy, mm, dd) age_in_days = (today-dob).days age_in_years = age_in_days/365 return int(age_in_years) def weight1(self): weight_in_kgs = weight/0.454 return int(weight_in_kgs)