In: Computer Science
Write a program named t03.py that tests the function by asking the user to enter a number and displaying the output day, month and year. Save the function in a PyDev library module named functions.py
A sample run for t03.py:
Enter a date in the format MMDDYYYY: 05272017
The output will be:
27/05/2017
The function docstring is as follows:
def convert_date (date_int): """
-------------------------------------------------------
Converts date_int into days, month and year use: day,month,year = convert_date (date_int)
-------------------------------------------------------
Paramaters:
date_int – (int > 0)
returns
day: the day in the month in date_int (int >= 0)
month: the month in date_int (int >=0) year: the years in date_int (int >=0)
------------------------------------------------------- """
Program Code Screenshot:
Sample output:
The screenshots are attached below for reference.
Please follow them for proper indentation and output.
Program to
copy:
def convert_date (date_int):
temp=date_int
c=0
res=""
while temp!=0:#getthe number of digits
temp=temp//10
c+=1
if(c==7):#if number of digits is 7 then it means that 0 is present
in first place
k=date_int//100000#perform arithmetic operations on the date_int
and print the results
print((k%10),end="")
k=date_int//10000
print(k%10,end="")
print("/"+"0",end="")#print the / characters and add 0
print((date_int//1000000),end="")
print("/",end="")
k=date_int%10000
print(k)
else:
k=date_int//10000
print(k%100,end="")
print("/",end="")
k=date_int//1000000#perform arithmetic operations on the date_int
and print the results
print((k),end="")
print("/",end="")
k=date_int%10000
print(k)
date=int(input("Enter a date in the format MMDDYYYY:"))#read
input of integer type
convert_date(date)#call function
Note:
Please let me know in case of any help needed in the comments
section.