Braincode
11th November 2011, 02:52 PM
buat para juragan skalian, saya minta sarannya soal optimasi kode di python. berikut saya bikin program buat menghitung umur, sudah seminggu saya otak atik nih kode, cuma rasanya masih kurang "sreg" aja, kodenya ada di bawah gan.
01 ################################################
02 #age_counter.py
03 name = raw_input("input your name")
04
05 #birth date input
06 bdate = input ("birth date")
07 bmonth = input ("brith month")
08 byear = input ("birth year")
09 birth = bdate + (bmonth * 30) + (byear * 365)
10
11 #present date input
12 tdate = input ("today date")
13 tmonth = input ("today month")
14 tyear = input ("today year")
15 today = tdate + (tmonth * 30) + (tyear * 365)
16
17 #begin processing
18 age = (today - birth) / 365 #years
19 month = ((today - birth) % 365) / 30 #month
20 day = ((today - birth) % 365) % 30 #days
21
22 #print the result
23 print "dear", name, "your age is"
24 print day, " days", month, " months", age, " years old"
25
26 #age commentation
27 if age
01 ################################################
02 #age_counter.py
03 name = raw_input("input your name")
04
05 #birth date input
06 bdate = input ("birth date")
07 bmonth = input ("brith month")
08 byear = input ("birth year")
09 birth = bdate + (bmonth * 30) + (byear * 365)
10
11 #present date input
12 tdate = input ("today date")
13 tmonth = input ("today month")
14 tyear = input ("today year")
15 today = tdate + (tmonth * 30) + (tyear * 365)
16
17 #begin processing
18 age = (today - birth) / 365 #years
19 month = ((today - birth) % 365) / 30 #month
20 day = ((today - birth) % 365) % 30 #days
21
22 #print the result
23 print "dear", name, "your age is"
24 print day, " days", month, " months", age, " years old"
25
26 #age commentation
27 if age