【python】石头剪刀布,模拟十次并统计获胜次数

0a8d5751b37643dd9b885180457c2c94.png

解决问题

下面是一个使用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 ==

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值