1. 程式人生 > >python實現石頭剪刀布遊戲

python實現石頭剪刀布遊戲

這是新手的第一個小程式,望大佬多多指教!謝謝!

# 石頭剪刀布
import random
player = input("請輸入您要出的拳 石頭(1)/剪刀(2)/布(3):")
choice = ['1', '2', '3']
computer = random.sample(choice, 1)
computer_1 = computer[0]
print("玩家選擇的拳頭是 %s - 電腦出的拳是 %s" % (player, computer_1))
if (player == '1' and computer_1 == '3') or (player == '2' and computer_1 == '3') or (player == '3' and computer_1 == '1'):
    print("電腦弱爆了!")
elif player == computer_1:
    print("心有靈犀!")
else:
    print("不服氣,再來!")