Python基础实现与电脑对战的剪刀石头布小游戏,练习if while输入和输出

通过剪刀石头布小游戏,练习python的if while  print input

# 实现剪刀石头布小游戏
import  random # import 引入其他模块
'''
多行注释
'''

# 程序的入口
if __name__ == '__main__':
    # 1、定义菜单
    print("======欢迎中软游戏========")
    print("1、开始游戏")
    print("2、退出游戏")
    cmdLine = input("请输入选项:")
    while True:
        if cmdLine == "1":
            print("游戏开始,游戏提示:1、剪刀,2、石头,3、布")
            # 2、电脑出拳
            computer = str(random.randint(1, 3))
            # 3、人出拳
            player = input("请出拳:")

            # 4、判断输赢
            if computer == player:
                print("平局")
                pass
            elif computer == "1" and player == "2": # {} == 缩进 else if elif  &&  and or not
                print("你赢了,电脑出的剪刀")
                pass
            elif computer == "1" and player == "3":
                print("你输了,电脑出的剪刀")
                pass
            elif computer == "2" and player == "1":
                print("你输了,电脑出的石头")
                pass
            elif computer == "2" and player == "3":
                print("你赢了,电脑出的石头")
                pass
            elif computer == "3" and player == "1":
                print("你赢了,电脑出的布")
                pass
            elif computer == "3" and player == "2":
                print("你输了,电脑出的布")
                pass
            pass

        cmdLine = input("继续游戏吗?y/n:")
        if cmdLine != 'y':
            break
        else:
            cmdLine = "1"
        pass
    pass

 

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值