python學習-6 猜拳小遊戲

import random                       # 調用隨機數模塊
pc = random.randint(1,3)            # 產生1-3的隨機數

print("來玩個猜拳遊戲吧!")

a = '石頭'
b = '剪刀'
c = ''

user = input('請輸入(石頭,剪刀,布):')

if user == '石頭':
    print("你出了石頭")
elif user == '剪刀':
    print("你出了剪刀")
else:
    print("你出了布")


if pc == 1:
    print('電腦出了石頭')
elif pc == 2 :
    print('電腦出了剪刀')
else:
    print('電腦出了布')


if user == '石頭' and pc == 2 or user =='剪刀' and pc == 3 or pc == 3 or user == '' and pc == 1:
    print("你贏了")
elif user == '石頭' and pc ==3 or user == '剪刀' and pc == 1 or user == '' and pc == 2:
    print('你輸了')
else:
    print('平局')
相關文章
相關標籤/搜索