Wednesday, 14 August 2013

Python (2.7.5.) need assistance with calendar module

Python (2.7.5.) need assistance with calendar module

This is the sample question I got:
Create a Python program weekday.py that reads the input from the form. To
determine the day of the week, you can use a function from the calendar
module. The weekday function can be called like this:
weekday = calendar.weekday(y, m, d)
... assuming you have the year, month, and day in variables y, m, and d.
This will put an integer 0 - 6 in the variable weekday, where 0 is Monday,
1 is Tuesday, and so on.
Use a series of if statements to produce output like this on the generated
page (with the appropriate weekday, of course - this is what you'd produce
if the weekday was 0):
<p>That's a Monday.</p>
This is my what is did so far:
Python (newer version):
import cgi
import calendar
form = cgi.FieldStorage()
print "Content-type: type/html"
print
y = form['year'].value
m = form['month'].value
d = form['date'].value
weekday = calendar.weekday(y, m, d)
if weekday == 0:
print "<p> That's monday </p>"
if weekday == 1:
print "<p> That's tuesday </p>"
if weekday == 2:
print "<p> That's wednesday </p>"
if weekday == 3:
print "<p> That's thursday </p>"
if weekday == 4:
print "<p> That's friday </p>"
if weekday == 5:
print "<p> That's saturday </p>"
if weekday == 6:
print "<p> That's sunday </p>"
Can someone please help me?? I would greatly appreciate it. Thank you!

No comments:

Post a Comment