根據(jù)知識(shí)點(diǎn)蕉拢,自己寫(xiě)了一個(gè)猜拳小游戲:
import random
def check():
? ? check_input = True
? ? while check_input:
? ? ? ? check = int(input('請(qǐng)輸入0,1或2爆捞。0代表石頭,1代表布绪钥,2代表剪刀'))
? ? ? ? if check not in (0,1,2):
? ? ? ? ? ? print('由于您不按規(guī)則輸入咆霜,該局已判斷為負(fù)')
? ? ? ? else:
? ? ? ? ? ? check_input = False
? ? ? ? return check
def cai_quan(turn):
? ? v1_count = 0
? ? v2_count = 0
? ? for t in range(turn):
? ? ? ? print(f'round{t+1}')
? ? ? ? p1 = check()
? ? ? ? p2 = random.randint(0,2)
? ? ? ? if (p1 - p2) == 1 or (p1 - p2) == -2:
? ? ? ? ? ? print('Player win!')
? ? ? ? ? ? v1_count += 1
? ? ? ? elif p1 == p2:
? ? ? ? ? ? print('Draw!')
? ? ? ? else:
? ? ? ? ? ? print('Computer win!')
? ? ? ? ? ? v2_count += 1
? ? print(f'{turn} games,you win {v1_count} turns, and computer wins {v2_count} turns.')
cai_quan(3)