# WORD Jumble猜單詞遊戲
import random
# 建立單詞序列
WORDS = ("aaa","sss","abc")
# 開始遊戲
print(
"""
歡迎參加猜單詞遊戲
把字母組合成一個正確的單詞。
"""
)
iscontinue = "y"
while iscontinue == "y" or iscontinue == "Y":
# 從序列中隨機挑出一個單詞
word = random.choice(WORDS)
# 一個用於判斷玩家是否猜對的變量
correct = word
# 建立亂序後單詞
jumble = ""dom
while word: # word不是空串循環
# 根據word長度產生word的隨機位置
position = random.randrange(len(word))
# 將position位置的字母組合到亂序後單詞
jumble += word[position]
# 經過切片將position位置的字母從原單詞中刪除
word = word[: position] + word[(position + 1):]
print("亂序後單詞:", jumble)blog
guess = input("\n 請你猜:")
while guess != correct and guess != "":
print("對不起不正確。")
guess = input("繼續猜:")遊戲
if guess == correct:
print("真棒,你猜對了!\n")
iscontinue = input("\n 是否繼續(Y/N)")input
============================================================================it
運行結果截圖:io