Ceriwis  

Go Back   Ceriwis > HOBI > Komputer & Teknologi > Programming

Programming Share, tanya jawab, saling bantu antar programmer dengan berbagai macam bahasa pemrograman.

Reply
 
Thread Tools
  #1  
Old 11th November 2011
Braincode's Avatar
Braincode Braincode is offline
Ceriwis Addicted
 
Join Date: Nov 2011
Posts: 4,638
Rep Power: 20
Braincode mempunyai hidup yang Normal
Default [ask] optimasi kode python

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

Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


 


All times are GMT +7. The time now is 01:24 AM.


no new posts