python 石头剪刀布游戏

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")
    
        


你可能感兴趣的:(游戏,python,String,input,import)