- Python
python 字符串和列表综合运用-【猜单词游戏】
- 2024-9-15 10:01:47 @
import random
# 游戏界面
print('''
***********************************
欢迎来到猜单词游戏
请选择:
1.乱序猜单词
2.提示中文猜英文单词
***********************************
''')
# choice = input("请输入1或者2:")
# 正确单词列表
word_list = ["apple", "banana"]
chinese_list = ["苹果","香蕉"]
# 随机选择一个单词
chosen_word = random.choice(word_list)
# 打乱单词顺序
shuffled_word = ''.join(random.sample(chosen_word, len(chosen_word)))
# 游戏主循环
while True:
# 显示乱序单词
print("欢迎来到猜单词游戏!")
print("乱序单词是:", shuffled_word)
print("请输入你猜的单词:", end=' ')
# 收集玩家输入
guess = input()
if guess =='t':
print("中文提示:", chinese_list[word_list.index(chosen_word)])
print("请输入你猜的单词:", end=' ')
# 收集玩家输入
guess = input()
# 判断是否猜对
if guess == chosen_word:
print("恭喜你猜对了!")
print("游戏结束。")
break
else:
print("猜错了,请再试一次。")
# 询问玩家是否继续
continue_game = input("是否想要继续游戏?(yes/no): ")
if continue_game.lower() != 'yes':
print("感谢你的参与,游戏结束。")
break
# 重置游戏
chosen_word = random.choice(word_list)
shuffled_word = ''.join(random.sample(chosen_word, len(chosen_word)))
0 条评论
目前还没有评论...