Jump to content

Weekday generator

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
taabistan

taabistan

    Newbie

  • Members
  • Pip
  • 7 posts
The program is simple. You write the date (day #, month, year) and the program will tell you what day of the week it was.

Here is the link to my attempt:

Day of the Week

Here is my xHTML code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>

<title>Day of the Week</title>

</head>

<body>


<h1>Day of the Week</h1>


<form action="weekday.py">

<p>

Enter the date (yyyy, mm, dd): 

<input type="text" name="year" size="4" maxlength="4" />

<input type="text" name="month" size="2" maxlength="2" />

<input type="text" name="day" size="2" maxlength="2" />


</p>

<p>

<input type="submit" value="Give me the weekday" />

</p>


</form>


</body>

</html>


Here is my python code:

#!/Python26/python

import calendar, cgi

import cgitb; cgitb.enable()


form = cgi.FieldStorage()


day = form.getvalue('day')

if day:

    day = int(day)

month = form.getvalue('month')

if month:

    month = int(month)

year = form.getvalue('year')

if year:

    year = int(year)

weekday = form.getvalue('weekday')

if weekday:

    weekday = int('weekday')



def getDay(day):

    if  (weekday == 0):  

        day = "Monday"

    elif (weekday == 1):

        day = "Tuesday"

    elif (weekday == 2):

        day = "Wednesday"

    elif (weekday == 3):

        day = "Thursday"

    elif (weekday == 4):

        day = "Friday"

    elif (weekday == 5):

        day = "Saturday"

    else:

        day = "Sunday"

    return day



print "Content-Type: text/html\n\n"

print "<head>"

print "<title>Weekday</title>"

print "</head>"

print "<body>"

print "<p>That's a %s</p>" % (getDay(weekday))

print "</body>" 


Any help would be much appreciated. It seems like all answers come out as Sunday

#2
Vladimir

Vladimir

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
Check my answer here how to rewrite you function: http://forum.codecal...html#post283431

There are 2 errors in your code:

weekday = int('weekday') # first

Second:

def getDay(day): # second

I think you are able to fix them yourself :)