16-if实现石头剪刀布

import random
all_choices = ['石头','剪刀','']
computer = random.choice(all_choices)
player = input('请出拳: ')

print('Your choice:', player, "Computer's choice:", computer) 
# 另外一种写法:
# print("Your choice: %s, Computer’s choice: %s" %(player,computer))
if player == '石头':
    if computer == '石头':
        print('平局')
    elif computer == '剪刀':
        print('You WIN!!!')
    else:
        print('You LOSE!!!')

if player == '剪刀':
    if computer == '石头':
        print('You LOSE!!!')
    elif computer == '剪刀':
        print('平局')
    else:
        print('You WIN!!!')

if player == '':
    if computer == '石头':
        print('You WIN!!!')
    elif computer == '剪刀':
        print('You LOSE!!!')
    else:
        print('平局')

输出:

 

 

转载于:https://www.cnblogs.com/hejianping/p/10858230.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个C语言实现石头剪刀布小游戏,可以控制胜率的示例代码: ```c #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int play, computer, winCount = 0, loseCount = 0, drawCount = 0; char choice; srand(time(NULL)); do { printf("请选择:\n"); printf("1. 头\n"); printf("2. 剪刀\n"); printf("3. 布\n"); printf("0. 退出\n"); scanf("%d", &play); if (play == 0) { break; } computer = rand() % 3 + 1; printf("你选择了:"); switch (play) { case 1: printf("头\n"); break; case 2: printf("剪刀\n"); break; case 3: printf("布\n"); break; default: printf("无效选择\n"); continue; } printf("电脑选择了:"); switch (computer) { case 1: printf("头\n"); break; case 2: printf("剪刀\n"); break; case 3: printf("布\n"); break; } if (play == computer) { printf("平局!\n"); drawCount++; } else if ((play == 1 && computer == 2) || (play == 2 && computer == 3) || (play == 3 && computer == 1)) { printf("你赢了!\n"); winCount++; } else { printf("你输了!\n"); loseCount++; } printf("胜利次数:%d,失败次数:%d,平局次数:%d\n", winCount, loseCount, drawCount); printf("是否继续游戏?(y/n) "); scanf(" %c", &choice); } while (choice == 'y' || choice == 'Y'); return 0; } ``` 这个程序使用了随机数生成电脑的选择,然后根据玩家和电脑的选择进行比较,判断胜负或平局,并统计胜利、失败和平局的次数。你可以通过多次运行程序来控制胜率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值