首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在python中暂停脚本?

如何在python中暂停脚本?
EN

Stack Overflow用户
提问于 2018-07-26 05:43:32
回答 1查看 0关注 0票数 0

我有一个程序,我需要在程序之间停5秒:

print("Hello")
#pause here for 5 seconds
print("How are you?")
#pause here for 5 seconds
x = input("What is 2+2?")
if x == '4':
 print("Correct")
 #pause here for 2 seconds
 print("Bye!")
 exit()
else:
 print("Wrong, it's 4")
 #pause for 2 seconds
 print("Bye!")
 exit()

我该如何停下来等待我想要的时间?

EN

回答 1

Stack Overflow用户

发布于 2018-07-26 14:51:06

使用time.sleep(sec)

import time
print("Hello")
time.sleep(5)
print("How are you?")
time.sleep(5)
x = input("What is 2+2?")
if x == 4:
 print("Correct")
 time.sleep(2)
 print("Bye!")
 exit()
else:
 print("Wrong, it's 4")
 time.sleep(2)
 print("Bye!")
 exit()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100005797

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档