在python中导入随机单词并需要建议

时间:2018-08-15 16:06:00

标签: python python-requests

words = requests.get("http://svnweb.freebsd.org/csrg/share/dict/words?view=co&content-type=text/plain").content.splitlines()
secret_word = "Levinson"     
secret_word = secret_word.lower()

length = int(len(secret_word))
hint = ""
hint_list = list()
guess = ""
guess_count = 0
guess_limit = len(secret_word)/2
out_of_guesses = False

for i in range(length)     
    hint_list.append("_")
    i += 1
    i = 0

while guess != secret_word and not(out_of_guesses):
    if guess_count < guess_limit:
        print(hint_list)
        guess = input("Enter guess :")
        guess_count += 1
        hint_list[i] = secret_word[i]
        i += 1
    else:
        out_of_guesses = True
if out_of_guesses:
    print("You loose :(")
else:
    print("You Win!!")``

1 个答案:

答案 0 :(得分:0)

您可以从Unix words file中读取随机单词。单词文件通常存储在/usr/share/dict/words/usr/dict/words中。