这是我得到的示例问题:
创建一个 Python 程序 weekday.py,它从表单中读取输入。要确定星期几,您可以使用日历模块中的函数。weekday 函数可以这样调用:
weekday = calendar.weekday(y, m, d)
y
...假设您在变量,m
和中具有年、月和日d
。这会将整数 0 - 6 放入变量weekday
中,其中 0 是星期一,1 是星期二,依此类推。使用一系列
if
语句在生成的页面上产生类似这样的输出(当然,在适当的工作日 - 如果 为 0,这就是你会产生的weekday
结果):<p>That's a Monday.</p>
这是我到目前为止所做的:
Python(较新版本):
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>"
有人可以帮帮我吗??我将不胜感激。谢谢!