python 中的延迟
我在 python 上创建了一个问答游戏,基本上用户回答了我随机提出的一些问题,然后按 Enter 键,它会说“计算你的聪明度”,并会在屏幕上显示一个随机数字。 问题是,每次用户按下回车键时,它都会说“计算你的聪明度”并同时显示数字。我想知道如何在开始下一个代码/行/脚本之前添加延迟。?
这是我到目前为止的代码
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")
,谢谢。 :)
I Created a quiz game on python, where basically the user answers some questions i randomly made up and after that they press enter, it will say " calculating you smartness " and will show a random number on your screen.
problem is,everytime the user press enter it will say "calculating your smartness" and shows the number at the same time. im wondering how to add a delay before starting the next code/line/script.?
here is my code so far
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")
please and thank you. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
time 模块的 sleep()
另外,由于某种原因您已经导入了它。
time module's sleep()
Also, you already have it imported for some reason.
使用
time.sleep(secs)
,请参阅此处:http ://docs.python.org/library/time.html#time.sleepuse
time.sleep(secs)
, see here: http://docs.python.org/library/time.html#time.sleep您正在寻找 time.sleep()。
You're looking for time.sleep().