Python--用循环完成一个猜单词的小游戏

Python--用循环完成一个猜单词的小游戏,第1张

运用random模块 random.choice(words) random.randrange() len()全局函数 使用切片 [参数1:参数2:step]
import random
WORDS = ("python","import","hello","difficult","easy")
print("欢迎来到猜单词游戏,请将乱序后的单词组成正确的单词")
iscontinue = "y"
while iscontinue == "y" or iscontinue == "Y" or iscontinue == "yes" or iscontinue == "YES":
	words = random.choice(WORDS)
	right = words
	print(words)
	newwords = ""
	while words:
		position = random.randrange(len(words))
		newwords += words[position]
		words = words[:position] + words[position + 1:]
	print("乱序后的单词是:",newwords)
	guess = input("请你猜单词:")
	while guess != right and guess != "":
		print("抱歉,你猜错了!")
		guess = input("请你继续猜:")
	if guess == right:
		print("恭喜你猜对了!")
		iscontinue = input("你是否继续游戏Y/N:")

 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/797447.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-06
下一篇 2022-05-06

发表评论

登录后才能评论

评论列表(0条)

保存