猜单词

作者: 豆约翰 | 来源:发表于2019-05-05 13:18 被阅读0次

    '''
    计算机从一组单词中随机挑一个出来,然后对其进行乱序(也就是让单词的字母随机排列)。玩家要猜出原始单词才算赢。由此可以大致总结程序的主要流程:
    1.先构建一组单词,作为数据来源,方便测试;
    2.随机选择一个单词,并进行乱序,将乱序后的结果输出,供玩家猜测;
    3.根据玩家的猜测结果,输出对应的信息
    '''
    import random#引进随机模块

    set up dictionary

    dictionary=("augment","encompass","scramble","prospective","reinstate",
    "primordial","inexorable","discard","vigorous","commuter",
    "appetite","grumble","mechanical","aesthetic","stereotype",
    "compliment","civilization","discriminate","curse","sarcasm",
    "insane","recipe","reinforce","jealous","anniversary")#建立单词库,以元组的形式
    right="Y"
    print("Welcome to Word Guess!\n\n")
    while right=="Y":

    randomly choose a vocabulary

    word=random.choice(dictionary)#随机挑选一个单词
    score=100
    correct=word
    

    break word #将选出的单次进行乱序

    new_word=""
    for iin correct:
    

    position=random.randrange(len(word))
    new_word+=word[position]
    word=word[:position]+word[(position+1):]#序列的索引,切片等操作

    welcome interface

    print("The broken word is:",new_word)
    

    user need to guess

    guess=input("Please input your guess:")#玩家进行猜测
    while score>=60:
    

    if guess!=correct:
    guess=input("please try again:")
    score-=10;
    else:
    print("Congratulation!Your final score is:",score)
    break
    if score<60:
    print("Sorry,you are failed!")
    right=input("Play again?Y/N")#如果想继续玩,则输入Y
    print("Thanks for playing!")
    input("\n\n Press the enter key to exit")

    相关文章

      网友评论

          本文标题:猜单词

          本文链接:https://www.haomeiwen.com/subject/fpicoqtx.html