【发布时间】:2016-11-27 23:24:32
【问题描述】:
游戏与行话略有不同,因为可以使用任何字长。我怎样才能让我的程序打印一个?当字母在单词中但不在正确的位置时?如果字母在正确的位置,我如何让它打印实际的字母?例如单词是“tank”并且用户输入“town”它应该打印“t--?”我让一切正常工作,直到我必须让我的代码输出除“-”以外的字符 (这些词是荷兰语,但这不应该有任何区别)
import random
wordlist = ["hond", "haas", "neus", "peer","fruit", "laptop","raam","computer", "python", "hakan", "akkas", "mohammed", "amine", "school","informatica"]
word = random.choice(wordlist)
print("Your secret word has ", len(word), "letters")
while True:
guessword = input("Guess the word:")
if len(Guessword) != len(word): print("type a word with", len(word),"letters")
elif guessword == word: break
elif guessword != word:
if guessword != word: print("-" * len(word))
print("Congratulations, you guessed the word correctly!")
我还必须让游戏告诉你猜单词需要多少回合,并实施基于休息时间的评分系统。
编辑:必须尽可能紧凑
【问题讨论】:
标签: python-3.x