初学者,求一程序润色

凌虚|advance

2009-11-15 13:20:19 来自: 凌虚|advance(united & dialectical mind)

我是高中生,今年高三。这个是本人暑假时做英语阅读使用的秒表(2009年8月3日制作)。凭直觉觉得这个程序有瑕疵,但自己发现不了。所以来到这里,望高手赐教。
(使用方法:回车开始,再回车停止,再回车重新开始……。输入非空字符串回车结束。其实这个程序好理解)

from time import clock
clak1,clak2,tmstr,flag=0,0,'',False

while not tmstr:
tmstr = raw_input() # Just wait it
clak2=clock() # Get current time (in milliseconds)
# may use
# from ctypes import windll
# clak2 = windll.kernel32.GetTickCount()
# or
# clak2 = windll.winmm.timeGetTime()
# as well,
# but using the time module makes the program platform-independent
# so I chose the latter one. the data processing is different, of course.
if flag and not tmstr:
el=clak2-clak1 # el stands for elapsed time
hr=int(el/3600)
el%=3600
minit=int(el/60)
el%=60
sec=int(el)
# el may suffered a lot from float processing so I recalculated
# i don't know if it's necessary to do that
# is there anybody who can help me?
millisec=((clak2-clak1)%1)*1000
print "%ihr %i' %i'' %f" % (hr, minit, sec, millisec)
flag = False
else:
clak1, flag=clak2, True

  • 水 如履薄冰

    2009-11-15 20:25:50 水 如履薄冰 (开始读经典CS大部头)

    前两句是要说明什么?

  • NightCrawler

    2009-11-15 20:36:00 NightCrawler (回忆2061)

    其实raw_input(‘prompt=')可以带个参数,用作提示语

  • 2009-11-15 20:45:25 azer

    import time

    def timing():
    raw_input('press Entern to begin.')
    begin = time.time() # record begin time
    raw_input('Begin timing, press Enter to end timing.')
    cost = time.time() - begin
    secs, mins = cost%60, cost//60
    mins, hours = mins%60, mins//60
    # if you want days
    # hours, days = hours%24, hours//24
    print 'cost time>>%dh:%dm:%ds' % (hours, mins, secs)

    while True:
    timing()
    ask = raw_input('do you want quit(yes/no)?')
    if ask.lower().count('y'):
    break

  • diwayou

    2009-11-16 20:05:18 diwayou (追求IT,成就IT)

    现在高中小孩都会写程序了,我高中的时候只是见过电脑


这个小组的成员也喜欢去   · · · · · · 

Django
Django (1351)
Vim
Vim (3286)
Google App Engine
Google App Engine (1427)
Linux
Linux (4227)
ubuntu
ubuntu (4541)
Ruby
Ruby (1154)