python 石头剪刀布游戏

本文介绍了一个简单的石头剪刀布游戏实现,包括用户输入、随机机器人选择和游戏结果判断。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import sys
import random
print("please select 1(rock),2(scissor),3(paper) and input quit to quit the game")
dicelement = {1:"rock",2:"scissor",3:"paper"}


def game(player):
    
    robot = random.randint(1,3)
    if player == robot:
        print("you are draw,the robot guess %s and you guess %s" % (dicelement[robot],dicelement[player]))
    elif player%3 + 1 == robot:
        print("you are winner,the robot guess %s and you guess %s" % (dicelement[robot],dicelement[player]))
    elif robot%3 + 1 == player:
        print("you are loser,the robot guess %s and you guess %s" % (dicelement[robot],dicelement[player]))


if __name__ == "__main__":
    
    print("Game Desciption:rock:1","scissor:2","paper:3")
    while 1:
        player = input("please input your lucky number choice:")
        if player == "quit":
            sys.exit()
        if not player.isdigit():
            print("please input number,not string")
            continue
        ichoice = int(player)
        if ichoice >= 1 and ichoice <= 3:
            game(ichoice)
        else:
            print("please input the number between 1 and 3")
    
        


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值