python - 我正在学习 python,请有人告诉我如何修复它,这样我就可以慢慢打印每个字母(就像打字机一样),但也可以使用输入
问题描述
door1 = input('\n\nthere are 3 doors ahead of you, \n\nwhich one do you pick? \n\n1,2 or 3.')
for char in door1:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.1)
我试图让代码慢慢打印问题,但是当我试图同时获得输入时我不知道如何做到这一点。
解决方案
你几乎拥有它!
import time,sys
door1 = '\n\nthere are 3 doors ahead of you, \n\nwhich one do you pick? \n\n1,2 or 3.'
for char in door1:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(0.1)
response = input()
之前,您正在以打字方式编写用户响应。你想把问题写成这样,所以我把 door1 改成了你的问题字符串。然后慢慢打印后,我把输入功能放在那里。
推荐阅读
- reactjs - 测试 Window.Location.Pathname 测试库 + jest
- spring - 使用 Spring Authorization Server 配置 Spring Gateway
- sql - 如果包含某些字符串 postgres 则拆分文本
- xamarin - 将参数后面的代码转换为 mvvm xamarin
- java - 如何从java字符串中删除最后第六个单词
- reactjs - 我如何使 echarts 与 react-grid-layout 一起调整大小?
- python - Nvidia Jetson GST Pipeline udpsrc 使用 Python3 到 appsink
- android - 如何在 Final Android App 中的 WebView 上添加 Imageview
- entity-framework - 实体框架实体继承和自定义属性
- javascript - 没有文本时隐藏下拉值