【发布时间】:2020-12-30 00:22:50
【问题描述】:
这是我延迟打印的后续问题。但是这次我在尝试输入 print_with_delay(text) 函数时被卡住了。在打印发生之后并且在我可以在控制台中输入任何内容之前它返回 None 。有什么办法可以解决这个问题?
代码:
import time
# Delay text function to create realism for console dialogues
# Counts the length of the string and applies this to the delay
# Greatly improves visibility in the code
# No more time.sleep() between all print dialogues
def print_with_delay(text):
delay = len(text) / 100 + 1.2
time.sleep(delay)
print(text)
# if not text:
# return text
def start_game():
username = input(print_with_delay("Hello adventurer, I am Tony Tales, and what is your name?"))
print_with_delay(f"Nice to meet you {username}.")
print_with_delay("They call me Tony Tales, because I am a very talented tale teller.")
create_story = input (print_with_delay("I can sense greatness from you. Would you like to create a story with me? [Y/N]"))
if create_story == "y" or create_story == "Y":
print_with_delay("Great!")
else:
print_with_delay("Oooh? That is disappointing. Here, take this!")
print_with_delay("Tony Tales stabs you with a Pointy Pen...")
print_with_delay("You feel dizzy and faint...")
print_with_delay("The story ended.")
exit()
输出:
Hello adventurer, I am Tony Tales, and what is your name?
NoneTim
Nice to meet you Tim.
They call me Tony Tales, because I am a very talented tale teller.
I can sense greatness from you. Would you like to create a story with me? [Y/N]
NoneY
Great!
【问题讨论】:
标签: python string input return console-application