石头剪刀布猜拳拳之Python简单实现

#猜拳拳
import random
import time

#游戏规则
def Game():
    kind = ['石头','剪刀','布']
    win = [("石头","剪刀"),("布","石头"),("剪刀","布")]
    robot = random.choice(kind)
    #print(robot)
    #time.sleep(0.5)
    Flag = True
    while Flag:
        Flag = False
        player = input("请您输入选项(剪刀、石头、布):")
        if player in kind:
            if player == robot:
                print ("棋逢对手,我们再来")
                Select()
            elif (player,robot) in win:
                print ("恭喜 %s ,你赢了" % name)
                Select()
            else:
                print ("很遗憾,你输了")
                Select()
        else:
            Flag = True

#选择
def Select():
    id = input("请输入选项对应的数字(1、继续游戏;2、重新开始;3、退出游戏):")
    if id=='1':
        Game()
    elif id=='2':
        Main()
    else:
        print("%s 已退出游戏" % name)

def Main():
    print ("******************欢迎来到菜鸟游戏******************")
    global name
    name = input("请您输入您的用户名:")
    print ("欢迎体验本游戏!")
    Game()

if __name__ == '__main__':
    Main()

python实验课小实践

你可能感兴趣的:(Python,python)