那麼,從概念上說,你的代碼是好的。你最大的錯誤是,聖誕節是(典型值)12月25日儘管如此,這裏有一些事情可以做,使你的代碼有點更簡潔:
import time
continueLooping = True
while continueLooping:
time.sleep(60)
dateChecker = time.strftime("%b, %d", time.localtime())
if dateChecker == "Dec, 25":
print "It's Christmas"
raw_input("Enter anything to close\n")
continueLooping = False
變化:
varthing
- >continueLooping
:您希望您的變量名稱能夠反映其預期用途。
= 1; == 1; = 0
- >= True; ; = False
:布林存在的原因。它們使你的代碼更加明確,更易於閱讀。此外,您必須編寫較少的代碼(
== 1
)。
checker
- >dateChecker
:您的變量名應具體到它們的使用情況下(只是櫃面你需要檢查別的東西了線)
"Dec, 24"
- >"Dec, 25"
:同樣,聖誕節往往是12月25日
否則,它最終很好。 raw_input
位似乎沒有太多,但這是一個用戶體驗的事情。
編輯:
看到如何總有一個更小的方式,我會盡量簡潔地嘗試這個(沒有很大的損失清晰度)。
import time
while time.strftime("%b, %d", time.localtime()) != "Dec, 25":
time.sleep(60)
print "It's Christmas"
現在我覺得我要把這件事上CodeGolf。
更改時鐘,而程序的運行方式。 –
投票結果如何? – zeboidlund
歡迎來到SO。重新發布[你的問題](http://stackoverflow.com/questions/8381192/i-have-no-idea-what-is-wrong-with-this-code)被認爲是有害的。如果你需要包括更多東西,你可以隨時編輯原始問題 – joaquin