猜拳小遊戲

2021-10-10 02:59:23 字數 875 閱讀 1137

#-*- coding=utf8 -*-

# @author:hk

# date: 2020/10/30

# 檔案說明 :

import random

count=

0win_c=

0com =

"y"while com==

"y":

count=count+

1 player =

input

("請猜拳\n"

) computer = random.choice(

["石頭"

,"剪刀"

,"布"])

win=[(

"石頭"

,"剪刀"),

("剪刀"

,"布"),

("布"

,"石頭")]

if(player,computer)

in win:

win_c=win_c+

1print

("玩家勝"

)elif player==computer:

print

("雙方平局"

)else

:print

("電腦勝"

) win_rate=

int(

(win_c/count)

*100

) com=

input

("遊戲是否繼續,繼續請按y並回車,退出請按任意鍵\n"

)print

("遊戲次數{}次,贏了{}次,勝率{}%"

.format

(count,win_c,win_rate)

)

猜拳小遊戲

作者沒事的時候,編寫了個猜拳小遊戲的 現在上傳分享給大家,如下 匯入產生隨機數的函式包 import random 設定迴圈的初始化條件 i 繼續 判斷i是否等於 繼續 字串,如果不等於則退出迴圈,遊戲結束 while i 繼續 電腦產生的隨機數 computer random.randint 1,...

猜拳小遊戲(python)

import random 載入模組random 隨機數 win 0 定義勝場 lose 0 定義敗場 dogfall 0 定義平局 while true while 迴圈 print 10 猜拳遊戲 10 遊戲開頭輸出 遊戲名 print 勝 s,敗 s,平 s win,lose,dogfall ...

python小遊戲(猜拳)

usr bin python import random choices 石頭 剪刀 布 computer random.choice choices 生成乙個隨機值 print 猜拳遊戲開始.print 請輸入數字 print 1.石頭 2.剪刀 3.布 while true guess num ...