为什么只显示功能和文本显示?
我一直在尝试将用户输入加在一起,从而将其逐一计算到零。有时候,我脑海中出现了,但我会取得意外的结果。我真的想知道为什么没有显示文本。感谢您的帮助。
import time
def timer():
for x in range(60,-1,-1):
print(x)
time.sleep(1.5)
input(f"Type code in {timer()} seconds : ")
I have been trying to make a user input with seconds together which counting down one by one till Zero. Sometimes somethings comes into my head but i take unexpected results. I am really wondering why the texts aren't being shown. Thanks for help from now.
import time
def timer():
for x in range(60,-1,-1):
print(x)
time.sleep(1.5)
input(f"Type code in {timer()} seconds : ")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
什么错...
您会遇到错误代码> timer()并尝试从中获取返回的值,然后用
f'type代码在{value}秒中打印它:'
。这就是为什么您将在屏幕上获得
60 ... 0
的计数,然后在非秒内输入代码:,为timer()
timer()< /代码>返回什么都没有(<代码>无
)。该怎么做...
渲染续订显示并尝试同时在命令提示符中获得用户输入是理想的,即使不是不可能。 (命令提示不适合幻想。)
为了实现您的目标,我建议使用UI(用户界面),这是一个简单的UI:
What is wrong...
You are getting error because when you call
input(f"Type code in {timer()} seconds : ")
, the program will runtimer()
and try to get the returned value from it, then print it withf'Type code in {value} seconds : '
.That is why you will get the count down of
60...0
on your screen, followed byType code in None seconds :
, astimer()
return nothing(None
).What to do...
Rendering a renewing display and trying to get user input at the same time in the command prompt is not ideal if not impossible. (Command prompt is not for fancy display.)
To achieve your goal, i suggest using an UI (user-interface), here is a simple UI to do it:
正如Tdelaney和Darryig在评论中所说的那样,在执行代码代码段时,它将输出60,59,58 ...,直到0,然后在0中显示“键入代码”:“我认为这是正确的结果。
仅在{}中放置一个简单的表达式(例如变量),代码代码段可以将表达式输出和文字输出。
上面的代码段将输出“在5秒内输入代码:”
As tdelaney and DarryIG said in the comment, when executing the code snippet, it will output 60,59,58..., until 0, and then display "Type code in None seconds : ", I think this is the right result.
only place a simple expression(such as a variable) in the {}, the code snippet can output the expression and literal together.
The code snippet above will output"Type code in 5 seconds : "