User:Emily/Prototyping/Trimester 03/04
birthday.cgi
- command line -- go to "http://localhost:8000/"
python -m CGIHTTPServer
birthday.py (datetime module)
Version I
import datetime
while True:
year = input("What year were you born?")
# or we can use --> year = raw_input("What year were you born?")
month = input("What month were you born?")
day = input("What day were you born?")
# print type(year), type(month)
try:
d = datetime.datetime(int(year), int(month), int(day))
print d.strftime("You were born on a %A")
# what does %A mean??
break
except ValueError:
print "Hey please only type only numbers!"
# pass
Version II (better)
import datetime
while True:
try:
year = int(raw_input("What year were you born?"))
# "input" is not working here, use "raw_iput"
month = int(raw_input("What month were you born?"))
day = int(raw_input("What day were you born?"))
# print type(year), type(month)
d = datetime.datetime(year, month, day)
print d.strftime("You were born on a %A")
break
except ValueError:
print "Hey please only type only numbers!"
# pass