猜单词游戏(python)
首先将需要猜测的单词保存
WORDS = ("python", "jumble", "easy", "difficult", "answer", "continue", "phone", "position", "position", "game")
将单词打乱(我写了一个方法)
def shuttle_(s):
s_=list(s)
random.shuffle(s_)
return ''.join(s_)
完整代码
import random
WORDS = ("python", "jumble", "easy", "difficult", "answer", "continue","phone", "position", "position", "game")
print("\t 欢迎参加猜单词游戏")
print("\t把字母组合成一个正确的单词.")
def shuttle_(s):
s_=list(s)
random.shuffle(s_)
return ''.join(s_)
def danci():
word = random.choice(WORDS)
print("乱序后单词:", shuttle_(word))
a=input('请你猜: ')
while 1 :
if a == word:
print('真棒,你猜对了!')
break
else :
a=input('猜错了,重新猜一次吧: ')
danci()
while(1):
b=input('是否继续(Y/N):')
if b=='Y' or b=='y':
danci()
else:
break
里面简单的还可以自己添加