1
私のプログラムの出力を1行に集めようとしていますが、 "end = ''"と表示されても動作していないようです。何か案は?ここで end = '' not working(Python)
が私のコードです:何らかの理由で、私のプログラムは、今import random
thesaurus = {}
with open('thesaurus.txt') as input_file:
for line in input_file:
synonyms = line.split(',')
thesaurus[synonyms[0]] = synonyms[1:]
print ("Total words in thesaurus: ", len(thesaurus))
# input
phrase = input("Enter a phrase: ")
# turn input into list
part1 = phrase.split()
part2 = list(part1)
newlist = []
for x in part2:
s = random.choice(thesaurus[x]) if x in thesaurus else x
s = random.choice(thesaurus[x]).upper() if x in thesaurus else x
newlist.append(s)
newphrase = ' '.join(newlist)
print(newphrase, end=' ')
をプリントアウトされます。入力 "私はりんごを食べるのが好き"
と
i LOVE FREEDOM
SUFFICIENCY apples
期待される出力は:
i LOVE FREEDOM SUFFICIENCY apples
です。 210
何か助けていただければ幸いです!