Q.
Write a Python program using only loops
(no functions, no lists, no libraries/modules)
to input a date in the format DD/MM/YYYY
and output it in the format shown below.
You must calculate the day of the week by
counting days from a reference date using
loops only.
Input Format:
A single string representing the date, in
DD/MM/YYYY format (e.g., 19/03/1680).
Reference Hint:
Assume that 19th March 1680 was a Monday.
Output Format:
Display the date in the format:
Monday, the 19th March,1680
d = input("Enter date in DD/MM/YYYY format: ")
dd = int(d[0]) * 10 + int(d[1])
mm = int(d[3]) * 10 + int(d[4])
yy = int(d[6]) * 1000 + int(d[7]) * 100 + int(d[8]) * 10
+ int(d[9])
ref_day = 19
ref_month = 3
ref_year = 1680
total_days = 0
curr_year = ref_year
while curr_year < yy:
if (curr_year % 4 == 0 and curr_year % 100 != 0) or
(curr_year % 400 == 0):
total_days = total_days + 366
else:
total_days = total_days + 365
curr_year = curr_year + 1
curr_month = ref_month
while curr_month < mm:
if curr_month == 2:
if (yy % 4 == 0 and yy % 100 != 0) or (yy % 400
== 0):
total_days = total_days + 29
else:
total_days = total_days + 28
elif curr_month == 4 or curr_month == 6 or
curr_month == 9 or curr_month == 11:
total_days = total_days + 30
else:
total_days = total_days + 31
curr_month = curr_month + 1
total_days = total_days + (dd - ref_day)
rem = total_days % 7
if rem == 0:
day_name = "Monday"
elif rem == 1:
day_name = "Tuesday"
elif rem == 2:
day_name = "Wednesday"
elif rem == 3:
day_name = "Thursday"
elif rem == 4:
day_name = "Friday"
elif rem == 5:
day_name = "Saturday"
else:
day_name = "Sunday"
if dd == 1 or dd == 21 or dd == 31:
suffix = "st"
elif dd == 2 or dd == 22:
suffix = "nd"
elif dd == 3 or dd == 23:
suffix = "rd"
else:
suffix = "th"
if mm == 1:
month_name = "January"
elif mm == 2:
month_name = "February"
elif mm == 3:
month_name = "March"
elif mm == 4:
month_name = "April"
elif mm == 5:
month_name = "May"
elif mm == 6:
month_name = "June"
elif mm == 7:
month_name = "July"
elif mm == 8:
month_name = "August"
elif mm == 9:
month_name = "September"
elif mm == 10:
month_name = "October"
elif mm == 11:
month_name = "November"
else:
month_name = "December"
final_output = day_name + ", the " + str(dd) + suffix +
" " + month_name + "," + str(yy)
print(final_output)