0

Why is [0:4], [4:6] and [6:8] needed for this?

import datetime class User: def __init__(self, full_name, birthday): self.name = full_name self.birthday = birthday def age(self): today = datetime.date(2020, 4, 4) 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_years = (today-dob).days return int(age_in_years) user = User("Aaditya Pageni", "20011206") print(user.age())

4th Apr 2020, 4:55 PM
Wakizu
Wakizu - avatar
2 Respostas
0
Birthday is the string "20011206". Start up a Python interpreter. At the ">>>" prompt, type: birthday = "20011206" and hit Enter. Now enter print(birthday) to check that it is the result that you expect. Now do: birthday[0:4] What do you get? How about birthday[4:6] and birthday[6:8]? Is it clear now?
4th Apr 2020, 5:12 PM
Wakizu
Wakizu - avatar
+ 2
Don't know if you got there, but if you had, take time for a review. https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2453/
4th Apr 2020, 5:00 PM
Ipang