'石頭0', '剪刀1', '布2'
'''
玩家 計算機
0 1 玩家獲勝
0 2 計算機獲勝
1 0 計算機獲勝
1 2 玩家獲勝
2 0 玩家獲勝
2 1 計算機獲勝
'''
import random player = int(input("請輸入整數['石頭0', '剪刀1', '布2']:")) while not player in [0,1,2]: player = int(input("輸入錯誤,請重新輸入整數0,1,2:")) computer = random.randint( 0,2 ) # compute = random.choice([0,1,2]) ls = ['石頭', '剪刀', '布'] # print(f'玩家出:{ls[player]}, 計算機出:{ls[computer]}{computer}') #檢視計算機出的數字 print(f'玩家出:{ls[player]}, 計算機出:{ls[computer]}') if (player == 0 and computer == 1) or (player == 1 and computer == 2) or (player ==2 and computer ==0): print("玩家獲勝!") elif player == computer: print('平局!') else: print('計算機獲勝!') ''' 玩家 計算機 0 1 玩家獲勝 0 2 計算機獲勝 1 0 計算機獲勝 1 2 玩家獲勝 2 0 玩家獲勝 2 1 計算機獲勝 '''