我是python的初学者。我正在尝试用python做一个游戏,叫做Jumble words游戏。我有"words.txt“,这是包括游戏和"High_score.txt”的所有单词,以存储球员获得的最高分数。我想知道如何加载数据结构中的".txt“文件。以及如何从a-z生成8个随机字母供玩家猜测。这个游戏就像程序会给用户8个随机的字母,玩家可以从2-8个字母中猜出与"words.txt“中的单词相匹配。并将最高分的30个存储在"High_score.txt“文件中。
发布于 2020-05-02 12:58:18
读取文件:
f = open("/path/to/file","r")
string = f.read()
随机字母:
import string
import random
mixedletters = ''.join(random.sample(s, len(s)))
https://stackoverflow.com/questions/61554599
复制相似问题