zoukankan      html  css  js  c++  java
  • 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("本游戏有如下两种规则:
    ")
        print("1:根据汉语猜测单词
    ")
        print("2:根据单词猜测汉语
    ")
        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("
    请你猜满足该汉语意思的单词: ")
                while guess != D2[word] and guess != "":
                    print("对不起不正确.")
                    guess = input("继续猜: ")
               
                if guess == D2[word]:
                    print("真棒,你猜对了!
    ")
                iscontinue=input("
    
    是否继续(Y/N):")
        elif a==2 :
            iscontinue="y"
            while iscontinue=="y" or iscontinue=="Y":    
                word=random.choice(list(D1.keys()))
                print("随机生成单词为:", word)
    
                guess = input("
    请你猜给定单词的汉语意思: ")
                while guess != D1[word] and guess != "":
                    print("对不起不正确.")
                    guess = input("继续猜: ")
               
                if guess == D1[word]:
                    print("真棒,你猜对了!
    ")
                iscontinue=input("
    
    是否继续(Y/N):")
        else:
            x=input("输入不合法是否重新输入(Y/N):")

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

     
     
  • 相关阅读:
    WinForm简单进度条
    金庸群侠传 3小时爆机
    One Day
    css组件化
    PHP判断端口是否打开的代码
    PHP下像JQUery下查找修改HYML元素的类PHP Simple HTML DOM Parser
    兼容IE和FF的添加收藏和设为主页代码
    注册成功啦,终于在博客园注册成功了,以后要更加努力的学习技术啊!
    ppz css栅格框架
    使用live writer 发布一下日志
  • 原文地址:https://www.cnblogs.com/pythonzhilian/p/13749201.html
Copyright © 2011-2022 走看看