Python 石头剪刀布

#!usr/bin/python
# -*- coding:UTF-8 -*-
from __future__ import print_function
import uniout
import random
import time
while 1:
    s = int(random.randint(1,3))#s的值为1~3的随机数,random.randint()获取随机数的函数
    if (s == 1):
        ind = "石头"
    else:
        if (s == 2):
            ind = "剪刀"
        else:
            ind = "布"
    m = raw_input("请输入石头、剪刀、布,或输入end结束:")
    time.sleep(1)
    mlist = ['石头','剪刀','布']
    if (m not in mlist) and (m != 'end'):
        print("您的输入不正确,请重新输入!")
    else:
        if (m not in mlist) and (m == 'end'):
            print("\n游戏退出,谢谢!.")
            break
        else:
            if (m == mlist):
                print("电脑出了",ind,"平局")
            else:
                if (m == '剪刀' and ind == '布')or(m == '石头' and ind == '剪刀')or(m == '布' and ind == '石头'):
                    print("电脑出了",ind,"恭喜你,你赢了!")
                else:
                    if (m == '剪刀' and ind == '石头') or (m == '石头' and ind == '布') or (m == '布' and ind == '剪刀'):
                        print("电脑出了",ind,"很遗憾,你输了!")










猜你喜欢

转载自blog.csdn.net/baidu_38763209/article/details/81197931
今日推荐