《目录》
01:time模块 (Time Module)
02:time模块II (Time Module II)
03:time模块III (Time Module III)
04:time模块IV (Time Module IV)
01:time模块
题目 时间函数举例1。
import time
if __name__ == '__main__':
print(time.ctime(time.time()))
print(time.asctime(time.localtime(time.time())))
print(time.asctime(time.gmtime(time.time())))
02:time模块II
题目 时间函数举例2。
import time
if __name__ == '__main__':
start = time.time()
for i in range(3000):
print(i)
end = time.time()
print(end - start)
03:time模块III
题目 时间函数举例3。
import time
if __name__ == '__main__':
start = time.process_time()
for i in range(100):
print(i)
end = time.process_time()
print('difference is %6.3f' % (end - start))
04:time模块IV
题目 时间函数举例4。
import time
import random
if __name__ == '__main__':
play_it = input('Do you want to play it? (\'y\' or \'n\') ')
while play_it == 'y':
c = input('Input a character: ')
i = random.randint(0, 2**32) % 100
print('Please input the number you guess: ')
start = time.process_time()
a = time.time()
guess = int(input('Input your guess: '))
while guess != i:
if guess > i:
print('Please input a little smaller')
guess = int(input('Input your guess: '))
else:
print('Please input a little bigger')
guess = int(input('Input your guess: '))
end = time.process_time()
b = time.time()
var = (end - start) / 18.2
print(var)
if var < 15:
print('You are very clever!')
elif var < 25:
print('You are normal!')
else:
print('You are stupid!')
print('Congratulations!')
print('The number you guessed is %d' % i)
play_it = input('Do you want to play it? (\'y\' or \'n\') ')