User:Emily/Prototyping/Trimester 03/04

From XPUB & Lens-Based wiki
< User:Emily
Revision as of 10:15, 13 June 2015 by Emily (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

birthday.cgi

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