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

python help def date(month, day, year): Accepting integers for the month (values

ID: 3864135 • Letter: P

Question

python help

def date(month, day, year): Accepting integers for the month (values from 1 to 12), the day (values from 1 to 31) and the year (values from 1 to 9999). Construct the correct date representation, as the examples below. You can assume that value of day is always a valid one for the given year and month. Restriction: you must use string formatting, either % or .format(). date(2, 29, 2016) rightarrow "02/29/2016" date(11, 8, 2008) rightarrow "11/08/2008" date(1, 3, 1) rightarrow "01/03/0001" def show_table (table): Given table as a list of lists of strings, create and return a formatted string representing the 2D table. Follow these requirements (examples below): Each row of the 2D table is on a separate line; the last row is followed by an empty line Each column is aligned to the left; Columns are separated with a single vertical bar '|'; and there must be exactly one space before and after the vertical bar; Every row starts and ends with a vertical bar; and there must be exactly one space after the leading bar and before the ending bar Restriction: you must use string formatting, either % or .format(). Assumption: every row of the 2D table has the same number of columns. The table has at least one row and one column.

Explanation / Answer

def Date(month,day,year):
   return "%02d/%02d/%04d"%(month,day,year)


print Date(2,29,2016)
print Date(11,8,2008)
print Date(1,3,1)

==============================================================

Output:

akshay@akshay-Inspiron-3537:~/Chegg$ python date.py
02/29/2016
11/08/2008
01/03/0001

======================================================================

def show_table(table):
   result = format(" | ")+" | ".join(" | ".join(map(str,l))+format(" | ") for l in table)
   result=result+" "
   print result


table=[["akshay","abhang"],["raj","shinde"],["jay","kadam"]]
show_table(table)

=======================================================================

Output:

kshay@akshay-Inspiron-3537:~/Chegg$ python table.py
| akshay   | abhang |
| raj   | shinde |
| jay   | kadam |