나는 사용자가 많은 시간 동안 무언가를 실행하는 프로그램을 만들고있다 (베타의 유휴 게임이다). 1 분 동안 타이머를 설정하고 프로그램이 몇 초 동안 실행되는 것을 발견했습니다.별로 눈에 띄지 않지만 이것이 루프를 실행하는 데 걸리는 시간 때문인지 궁금합니다. 이것은 내 코드입니다.
import time
foreverloop = True
automodeOn = False
idleSec = 0
idleMin = 0
pages = 0
pps = 0
while foreverloop:
if automodeOn == False:
msg = input("BTCG Command >> ")
if msg == 'auto':
autotime = input("How long would you like to go idle for? Answer in minutes.")
automodeOn = True
elif msg == 'autoMORE':
pps += .5
else:
pages += pps
print("You have auto-read",pps,"pages.")
idleSec += 1
if idleSec == 60:
idleSec = 0
idleMin += 1
if idleMin == int(autotime):
print("Idle mode turning off.")
automodeOn = False
time.sleep(1)
프로그램이 실행되는 데 걸리는 시간을 기다릴 수 있도록하는 대신 time.time()
시스템의 현재 UNIX 시간 (초)을 float로 가져오고 특정 시간이 경과 한 경우에만 계속합니다.
import time
time_begin = time.time()
wait_time = 60 # seconds to wait
while time.time() < time_begin + wait_time:
# do logic
print("Time passed:", time.time() - time_begin)
time.sleep(1) # can be whatever
print(wait_time, "seconds has passed!")
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다