0

だから私は学校のためにこれを理解しようとしています。x を 1 分ごとに出力しようとすると、10 分ごとに新しい行に出力されます。これまでのところ、毎分「printing x」を取得できません。誰か助けてください。これは私のコードです

import time;
inTime = float(input("type in how many second"))
oldTime = time.time()-inTime


print (time.time())

def tenMin(oldTime):
    newTime = time.time()
    if ((newTime - oldTime)>= 25):
        return True
    else:
        False

while (True):
        if (tenMin==True):
            print ("x")
            newTime = time.time()
            oldtime = time.time()
else:
    oldTime = time.time()
    continue
4

2 に答える 2

0

あなたの最初の問題はラインにあります

if (tenMin==True):

関数参照をブール値と比較すると、明らかに答えは False になります。パラメータを渡す必要があります

if (tenMIn(oldTime)):

...

于 2013-10-22T07:30:07.060 に答える
0

まず、コードにいくつかの問題があります。

  1. else: False- これは Python の正しい構文ではありません。

  2. タイマーが必要な場合、なぜユーザーに入力を求めるのですか?

  3. 論理的な問題があります:

    inTime = float(input("type in how many second"))

    oldTime = time.time()-inTime

    time.time は float ですが、ユーザーは UnixTime で何を印刷すればよいか本当にわかりますか?

簡単な解決策を提案します。これは最善ではありませんが、機能します。1分ごとに「x」が出力され、10分後に「\ n」(改行)が出力されます

import time

def main():

    #both timers are at the same start point
    startTimerTen = time.time()
    startTimerMin = startTimerTen

    while True:
        getCurrentTime = time.time()
        if getCurrentTime - startTimerTen >= 600:
            # restart both parameters
            startTimerTen = getCurrentTime
            startTimerMin = getCurrentTime
            print "This in 10 min!\n"
        if getCurrentTime - startTimerMin >= 60:
            # restart only min parameter
            startTimerMin = getCurrentTime
            print "x"


   #end of main
if __name__ == "__main__":
    main()
于 2013-10-22T08:00:26.930 に答える