代码:
import random
WORDS = ("python", "jumble", "easy", "difficult", "answer", "continue", "phone", "position", "result", "game")
print(
"""
欢迎参加猜单词游戏
把字母组合成一个正确的单词。
"""
)
iscontinue = "y"
while iscontinue == "y" or iscontinue == "Y":
word = random.choice(WORDS)
correct = word
jumble = ""
while word:
position = random.randrange(len(word))
jumble += word[position]
word = word[:position] + word[(position + 1):]
print("\n\n乱序后单词:", jumble)
guess = input("请你猜:")
while guess != correct and guess != "":
print("对不起不正确")
guess = input("继续猜:")
if guess == correct:
print("真棒,你猜对了!")
iscontinue = input("是否继续(Y/N):")
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
==== RESTART: C:/xuexi/pyrenwu/58718e95853d37756dfb0300711b4f92/第1周/34.py ====
欢迎参加猜单词游戏
把字母组合成一个正确的单词。
结果:
乱序后单词: s
请你猜:
==== RESTART: C:/xuexi/pyrenwu/58718e95853d37756dfb0300711b4f92/第1周/34.py ====
欢迎参加猜单词游戏
把字母组合成一个正确的单词。
乱序后单词: n
请你猜:answer
对不起不正确
继续猜:
————————————————
版权声明:本文为CSDN博主「qingkelan」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qingaini/article/details/126786496