Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

>>> import date >>> help( date ) >>> help( date.Date ) >>> x = date.Date() >>> x

ID: 664128 • Letter: #

Question

>>> import date

>>> help( date )

>>> help( date.Date )

>>> x = date.Date()

>>> x

>>> print( x )

Consider the Python statements shown below. Using the output produced by the commands above, predict what the output will be, then test your predictions by executing the statements.

import date

A = date.Date( 1, 1, 2014 )

print( A )

print( A.to_iso() )

print( A.to_mdy() )

print( A.is_valid() )

print() B = date.Date( 12, 31, 2014 )

print( B ) print( B.to_iso() )

print( B.to_mdy() )

print( B.is_valid() )

print()

C = date.Date()

C.from_iso( "2014-07-04" )

print( C )

print( C.to_iso() )

print( C.to_mdy() )

print( C.is_valid() )

print()

D = date.Date()

D.from_mdy( "March 15, 2015" )

print( D )

print( D.to_iso() )

print( D.to_mdy() )

print( D.is_valid() )

print()

E = date.Date()

print( E )

print( E.to_iso() )

print( E.to_mdy() )

print( E.is_valid() )

print()

3. Revise the program to test the behavior of the member function “__init__” when one or more of the arguments to that function are erroneous.

4. Revise the program to test the behavior of the member functions “from_iso” and “from_mdy” when the arguments to those functions are strings which contains spaces.

5. Revise the program to test the behavior of the member functions “from_iso” and “from_mdy” when the arguments to those functions are erroneous.

Explanation / Answer

A = date.Date( 1, 1, 2014 ) #intializes 1st January 2014
print( A ) #2014-01-01
print( A.to_iso() ) #2014-01-01T00:00:00+00:00
print( A.to_mdy() ) #01-01-2014
print( A.is_valid() ) #True

print() B = date.Date( 12, 31, 2014 ) #initializes 31st December 2014
print( B ) print( B.to_iso() ) #2014-12-31T00:00:00+00:00
print( B.to_mdy() ) #2014-12-31
print( B.is_valid() ) #True
print()
C = date.Date()
C.from_iso( "2014-07-04" ) #initializes 4th July 2014
print( C ) #2014-07-04
print( C.to_iso() ) #2014-07-04T00:00:00+00:00
print( C.to_mdy() ) #2014-07-04
print( C.is_valid() ) #True
print()
D = date.Date()
D.from_mdy( "March 15, 2015" )
print( D ) #2015-03-15
print( D.to_iso() ) #2015-03-15T00:00:00+00:00
print( D.to_mdy() ) #2015-03-15T00:00:00+00:00
print( D.is_valid() ) #True
print()
E = date.Date() #Initializes today's date
print( E ) # 2015-06-30
print( E.to_iso() ) #2015-06-30T00:00:00+00:00
print( E.to_mdy() ) #2015-06-30T00:00:00+00:00
print( E.is_valid() ) #True
print()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote