解决问题
下面是一个使用Python编写的剪刀、石头、布游戏的程序,包含玩家与计算机对战和模拟计算机对战10次的功能。
import random
def get_computer_choice():
return random.randint(0, 2)
def get_user_choice():
choice = input("请输入剪刀(0)、石头(1)、布(2): ")
while choice not in ['0', '1', '2']:
choice = input("输入无效,请输入剪刀(0)、石头(1)、布(2): ")
return int(choice)
def determine_winner(user_choice, computer_choice):
if user_choice == computer_choice:
return "平局,要不再来一局!"
elif (user_choice == 0 and computer_choice == 2) or \
(user_choice == 1 and computer_choice == 0) or \
(user_choice == 2 and computer_choice ==