猜单词游戏。计算机随机产生一个单词,打乱字母顺序,供玩家去猜 a.准备一组单词,随机抽取一个b.将抽取的单词作为答案,打乱字母顺序,显示给玩家,供其猜测c.猜测错误继续猜测或以空字符串.

import random      #随机函数
words =("conscietious","noteworthy")
i = random.randint(0,len(words)-1)          #随机单词的下标
b = list(words[i])            #将单词(字符串)转换成列表
random.shuffle(b)           #打乱字符列表的顺序
for j in range(len(b)):
    print("{} ".format(b[j]),end='')
    if j + 1 >= len(b):
        print()
a = input("Please input the word : ")
while a != ' ':
    if a == words[i]:
        print('Congratulation!\nGuess right!the word is "{}"'.format(words[i]))
        c = input("Do you want continue guess words?\ny:yes;n:no\nPlease choose: ")
        print()
        if c == "y" or c == "yes" :
            i = random.randint(0,len(words)-1)
            b = list(words[i])
            random.shuffle(b)
          

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值