python猜单词游戏代码_Python之猜单词游戏

最近上完python课,老师让用python中的字典写一个猜单词游戏,于是就自己写了一个代码,可用于自己背单词,如果觉得我写的单词太简单,可以改成自己想要背诵的单词。

代码可能存在瑕疵,还请大佬指教!!

# Word Jumble猜单词游戏

import random

#用字典创建单词序列

D1=dict(crawled='爬行',stimulate='刺激',difficult='困难',answer='回答',derive='得到',phone='手机',game='游戏'

,hello='你好',economic='经济',protocol='礼仪')

D2=dict(爬行='crawled',刺激='stimulate',困难='difficult',回答='answer',得到='derive',手机='phone',游戏='game'

,你好='hello',经济='economic',礼仪='protocol')

# start the game

print(

"""

欢迎参加猜单词游戏

根据汉语猜测单词,或者根据单词猜测汉语意思.

"""

)

x='y'

while x=='y' or x=='Y':

print("本游戏有如下两种规则:\n")

print("1:根据汉语猜测单词\n")

print("2:根据单词猜测汉语\n")

print("请输入你的选择:")

a=int(input())

if a==1 :

iscontinue="y"

while iscontinue=="y" or iscontinue=="Y":

word=random.choice(list(D1.values()))

print("随机生成汉语意思为:", word)

guess = input("\n请你猜满足该汉语意思的单词: ")

while guess != D2[word] and guess != "":

print("对不起不正确.")

guess = input("继续猜: ")

if guess == D2[word]:

print("真棒,你猜对了!\n")

iscontinue=input("\n\n是否继续(Y/N):")

elif a==2 :

iscontinue="y"

while iscontinue=="y" or iscontinue=="Y":

word=random.choice(list(D1.keys()))

print("随机生成单词为:", word)

guess = input("\n请你猜给定单词的汉语意思: ")

while guess != D1[word] and guess != "":

print("对不起不正确.")

guess = input("继续猜: ")

if guess == D1[word]:

print("真棒,你猜对了!\n")

iscontinue=input("\n\n是否继续(Y/N):")

else:

x=input("输入不合法是否重新输入(Y/N):")

本文首发于python黑洞网,博客园同步更新

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值