'''
計(jì)算機(jī)從一組單詞中隨機(jī)挑一個(gè)出來,然后對(duì)其進(jìn)行亂序(也就是讓單詞的字母隨機(jī)排列)嘁捷。玩家要猜出原始單詞才算贏蘑志。由此可以大致總結(jié)程序的主要流程:
1.先構(gòu)建一組單詞,作為數(shù)據(jù)來源局蚀,方便測(cè)試;
2.隨機(jī)選擇一個(gè)單詞恕稠,并進(jìn)行亂序琅绅,將亂序后的結(jié)果輸出,供玩家猜測(cè)谱俭;
3.根據(jù)玩家的猜測(cè)結(jié)果奉件,輸出對(duì)應(yīng)的信息
'''
import random#引進(jìn)隨機(jī)模塊
set up dictionary
dictionary=("augment","encompass","scramble","prospective","reinstate",
"primordial","inexorable","discard","vigorous","commuter",
"appetite","grumble","mechanical","aesthetic","stereotype",
"compliment","civilization","discriminate","curse","sarcasm",
"insane","recipe","reinforce","jealous","anniversary")#建立單詞庫,以元組的形式
right="Y"
print("Welcome to Word Guess!\n\n")
while right=="Y":
randomly choose a vocabulary
word=random.choice(dictionary)#隨機(jī)挑選一個(gè)單詞
score=100
correct=word
break word #將選出的單次進(jìn)行亂序
new_word=""
for iin correct:
position=random.randrange(len(word))
new_word+=word[position]
word=word[:position]+word[(position+1):]#序列的索引昆著,切片等操作
welcome interface
print("The broken word is:",new_word)
user need to guess
guess=input("Please input your guess:")#玩家進(jìn)行猜測(cè)
while score>=60:
if guess!=correct:
guess=input("please try again:")
score-=10;
else:
print("Congratulation!Your final score is:",score)
break
if score<60:
print("Sorry,you are failed!")
right=input("Play again?Y/N")#如果想繼續(xù)玩县貌,則輸入Y
print("Thanks for playing!")
input("\n\n Press the enter key to exit")