Python中的延迟
我用Python做了一个测验游戏,基本上就是用户回答我随便编的一些问题,然后按下回车键后,它会显示“正在计算你的聪明指数”,接着在屏幕上显示一个随机数字。
问题是,每次用户按下回车键时,它都会同时显示“正在计算你的聪明指数”和那个数字。我想知道怎么在开始下一段代码之前加一个延迟。
这是我目前的代码
import os
import time
a = raw_input("how old is I?:")
w = raw_input("How many ants are in the world?:")
e = raw_input("why am i asking so many questions:")
s = raw_input("Are mcdonalds food healthier than pizza huts?:")
o = raw_input("Are you fat:")
m = raw_input("show me examples of random:")
e = raw_input("how to eat a chicken without a chicken?:")
e = raw_input("Can you park in reverse while driving forwards while flying?:")
os.system('cls')
print "----------------------"
print "here are your answers!"
print a
print w
print e
print s
print o
print m
print e
print e
print "----------------------------------------------------------"
print 'now calculating smartness:'
print "Your smart level is:"
import random
print random.randint(1,100)
print "----------------------------------------------------------"
print "aw c'mon you can do better than that!!!!"
print "----------------------------------------------------------"
raw_input("Press enter to quit the game")
谢谢你! :)
3 个回答
1
你可以看看 time.sleep() 这个函数。
1
使用 time.sleep(secs)
,具体可以查看这里: http://docs.python.org/library/time.html#time.sleep
2
而且,你已经导入了这个模块,可能是出于某种原因。