import random
# 出拳
punches = ['石頭','剪刀','布']
computer_choice = random.choice(punches)
user_choice = ''
user_choice = input('請出拳:(石頭、剪刀、布)')? # 請用戶輸入選擇
while user_choice not in punches:? # 當用戶輸入錯誤,提示錯誤,重新輸入
? ? print('輸入有誤,請重新出拳')
? ? user_choice = input()
# 亮拳
print('————戰(zhàn)斗過程————')
print('電腦出了:%s' % computer_choice)
print('你出了:%s' % user_choice)
# 勝負
print('—————結(jié)果—————')
if user_choice == computer_choice:? # 使用if進行條件判斷
? ? print('平局!')
elif (user_choice == '石頭' and computer_choice == '剪刀') or (user_choice == '剪刀' and computer_choice == '布') or (user_choice == '布' and computer_choice == '石頭'):
? ? print('你贏了!')
else:
? ? print('你輸了!')