我正在尝试从文件中读取一个单词并随机选择一个单词。我可以选择一个随机单词,但是有些单词在单词后有额外的空格,例如缩进。我如何删除这个?import randomrandom_word = []secret_word = []def choose_secret_word(): infile = open("words.txt") for every_item in infile: random_word.append(every_item) secret_word = random.choice(random_word) print(secret_word)choose_secret_word()
添加回答
举报
0/150
提交
取消