程序很简单,最近爬虫写多了,换换口味。巩固一下基础,并不断的完善自己的代码风格,让代码更加规范。
同时我减少了注释,甚至根本没有加注释,因为,我觉得加注释只会让优雅的代码变得复杂。增加代码长度,而且以python语言的特性,读起来应该没有什么困难。就没加注释了,以后只会在非常重要的地方加注释,然后在函数声明后加说明文档。
给定一个单词列表,随机选一个单词,输入一个字母,如果再所选的字母中,就继续,且有次数限制。
选中的单词显示为单词长度个_,比如选中的是‘dog’。
效果如下:
image.png
import random
def pick_word(words):
return random.choice(words)
def factory(word, guess, s, list_word):
s[list_word.index(guess)] = guess
list_word[list_word.index(guess)] = '_'
def get_guess_word():
return input("Guess a letter?\ninput:")
def main(words):
word = pick_word(words)
time = TIME
list_word = list(word)
s = ['_' for i