魔术8球TXT文件列表
我需要我的随机响应是我存储在 txt 文件中的句子或字符串。 它只打印出一个单词而不是整行,我该如何解决这个问题,谢谢。
import random
import time
question = input("Ask the magic 8 ball a question (press enter to quit): ")
while question:
if question == "quit":
break
print("Let's see what your future holds")
print("Let me check real quick")
for i in range(random.randrange(3,10)):
print(". ",end=" ")
time.sleep(1)
print("\nYour answer is")
print("Your future is " + (random.choice(open("responses.txt","r").readline().split())) + " .")
question = input("Ask the magic 8 ball a question (press enter to quit): ")
print("See ya")
响应.txt: 可以肯定的是 无疑 你可以信赖它 是的,绝对是 确实如此 据我看来,是的 最有可能的 是的 前景良好 迹象表明是的 回复朦胧再试一次 现在最好不告诉你 稍后再询问 现在无法预测 集中精力再问一次 不要指望它 前景不太好 我的消息来源说不 非常怀疑 我的回答是不
I need my random responses to be the sentences or strings I have stored in my txt file.
It only prints out a single word instead of the whole line, how can I fix this, thanks.
import random
import time
question = input("Ask the magic 8 ball a question (press enter to quit): ")
while question:
if question == "quit":
break
print("Let's see what your future holds")
print("Let me check real quick")
for i in range(random.randrange(3,10)):
print(". ",end=" ")
time.sleep(1)
print("\nYour answer is")
print("Your future is " + (random.choice(open("responses.txt","r").readline().split())) + " .")
question = input("Ask the magic 8 ball a question (press enter to quit): ")
print("See ya")
response.txt:
It is certain
Without a doubt
You may rely on it
Yes definitely
It is decidedly so
As I see it, yes
Most likely
Yes
Outlook good
Signs point to yes
Reply hazy try again
Better not tell you now
Ask again later
Cannot predict now
Concentrate and ask again
Don’t count on it
Outlook not so good
My sources say no
Very doubtful
My reply is no
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确的方法是
解决您的问题
The correct way to do it is
This should solve your problem