#!/usr/bin/env python # coding: utf8 import random play = """(0) 剪刀 (1) 石頭 (2) 布 (.) 退出 Please input you choice: """ all_list = ["剪刀", "石頭", "布"] win_list = [["石頭", "剪刀"], ["剪刀", "布"], ["布", "石頭"]] while True: user = raw_input(play) if user == ".": break if user not in "012": print "無效的輸入,請輸入0/1/2/." continue computer = random.choice(all_list) userinput = all_list[int(user)] if userinput == computer: print "Computer Choice is %s\nYou Choice is %s\n平局" % (computer, userinput) elif [userinput, computer] in win_list: print "Computer Choice is %s\nYou Choice is %s\n你贏了" % (computer, userinput) else: print "Computer Choice is %s\nYou Choice is %s\n你輸了" % (computer, userinput)