1
I have a question, I can’t do an exercise in classes and methods.
2 - Create the class "Date" with the attributes: day, month, and year. And create the methods "setarData(receives day, month and year)" and "print("ex: 03/08/2017")". Constructor must initialize with 01/01/1970. USE OPTIONAL PARAMETERS.
The program must start with 01/01/1970 and must print the date the user enters. Ex: 03/08/2017
Imagery: http://imgur.com/a/sFOBv
- UPDATED IMAGE (I cannot import the class into the main program): http://imgur.com/a/NJN9H
What I managed to do, I stuck to that part...:
class Data:
def __init__(self, d = 1, m = 1, a = 1970):
self.dia = d
self.mes = m
self.ano = a
def setarData(self, d = 3, m = 8, a = 2017):
self.dia =
self.mes = m
self.ano = a
And what is the doubt?
– Woss
I wanted your help to solve the exercise. I have many doubts about how to create classes and methods and such. And I would like help...
– Pigot
But describe what exactly you’re missing.
– Woss
I don’t know how to go on. And I don’t even know if what I did is right
– Pigot
You don’t know how to do the
imprimir()
? The statement is a little weird, is that right? Even if you can understand it is a little ambiguous.– Maniero
Yes, that’s the statement...
– Pigot
I updated the topic with the image of the exercise. It is hosted in Imgur... I hope you understand now.
– Pigot
I still don’t understand the doubt.
– Maniero
Except for the wrong indentation within the class, the method definition is correct. By the way, in the method
setarData
lacked thed
inself.dia = d
.– Woss