第十關(guān)

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('你輸了!')

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 8月22日-----字符串相關(guān) 2-3 個性化消息: 將用戶的姓名存到一個變量中,并向該用戶顯示一條消息。顯示的消...
    future_d180閱讀 1,032評論 0 1
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,854評論 0 10
  • 從決定學(xué)習(xí)python到今天,已經(jīng)過去了好1個月,買的幾本書還沒一本看完的,慚愧。 忙不是借口,是時候來點計劃,來...
    快樂凍魚閱讀 7,355評論 0 1
  • #石頭剪刀布 import random #玩家輸入 player = 0 while player!='石頭' ...
    08c4a2d4d502閱讀 350評論 0 0
  • 前幾日一直在為一個視頻難受,越難受越會數(shù)次的找出來觀看,越看越難受!這個視頻我想大家都可能看過:是深圳一個挨打的女...
    寒蟬0520閱讀 442評論 3 8

友情鏈接更多精彩內(nèi)容