私は30文字列のリストを持っています。私は、ランダムモジュールのchoiceメソッドを使い、格納されているリストから新しい文字列を生成したいと思います。文字列を繰り返したくないので、すべての一意の文字列を一度印刷したいと思います。私はチャットボットを作成しようとしていますが、私は唯一のオーバー印刷する1つの文字列を取得することができ、すべての時間をかけて、私はあなたが必要random.choice with list
print("you are speaking with Donald Trump. If you wish to finish your conversation at any time, type good bye")
greetings = ["hello", "hey", "what's up ?", "how is it going?", ]
#phrase_list = ["hello", "the wisdom you seek is inside you", "questions are more important than answers"]
random_greeting = random.choice(greetings)
print(random_greeting)
open_article = open(filePath, encoding= "utf8")
read_article = open_article.read()
toks = read_article.split('"')
random_tok = random.choice(toks)
conversation_length = 0
responses = ''
while True: #getting stuck in infinite loops get out and make interative
user_response = input(" ")
if user_response != "" or user_response != "good bye":
responses = responses + user_response
conversation_length = conversation_length + 1
while conversation_length < 31:
print(random_tok)
if conversation_length >= 31:
print("bye bye")
あなたが含まれてくださいすることができあなたのコードスニペットも? – Unni
私は上記のコードを追加しました。それは表示されませんが、私はプログラムの冒頭にランダムにインポートしたものを貼り付けていませんでした – reubs