python猜拳小遊戲

2021-10-22 08:20:12 字數 832 閱讀 2556

import random

while true:

game =

player = input('請輸入:剪刀(0) 石頭(1) 布(2) 退出(3):')

# isdigit() 判斷字串是否為數字

if player.isdigit():

player = int(player)

# 退出遊戲

if player == 3:

print('退出成功,感謝你的使用!')

break

# 判斷是否出指定數字

if player not in game:

print('請輸入指定數字(0/1/2)!')

continue

else:

print('請輸入數字!')

continue

# 隨機整數(0,1,2)

computer = random.randint(0,2)

print('player出: %s, computer出: %s' % (game[player], game[computer]))

if (player == 0 and computer == 2) or (player == 1 and computer == 0) or (player == 2 and computer == 1):

print('你獲勝,哈哈,你太厲害了')

elif player == computer:

print('平局,要不再來一局')

else:

print('輸了,不要走,洗洗手接著來,決戰到天亮')

猜拳小遊戲(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 ...

python猜拳小遊戲

使用if else結構寫的乙個猜拳小遊戲 import random player input 請輸入 剪刀 0 石頭 1 布 2 player int player computer random.randint 0,2 print 電腦出的是 d computer if player0 and ...