User:Emily/Prototyping/Trimester 03/04: Difference between revisions
(Created page with "====birthday.cgi==== ====birthday.py (datetime module)==== <div style='width:90%;border:1px solid #ccc;padding:11px'> Version I ---- <source lang="python"> import dateti...") |
|||
Line 1: | Line 1: | ||
====birthday.cgi==== | ====birthday.cgi==== | ||
:command line -- go to "http://localhost:8000/" | |||
python -m CGIHTTPServer | |||
====birthday.py (datetime module)==== | ====birthday.py (datetime module)==== |
Revision as of 10:17, 13 June 2015
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