zoukankan      html  css  js  c++  java
  • Ai大学堂第十四章练习题

    #实现一个剪刀、石头、布的游戏,首先使用 random 模块的函数从列表 ['剪刀', '石头', '布'] 中随机选择一个,然后机器人玩家也随机出一个,比较两个,判断#玩家是输是赢。最后给出机器人玩家赢了几次,输了几次,平了几次。
    #提示:从列表 '剪刀', '石头', '布'] 随机选择,可以使用 random.choice(['剪刀', '石头', '布']

    import random
    #总测试次数
    x = 10
    #玩家赢的次数
    wins = 0
    #玩家输的次数
    bads = 0
    #玩家平的次数
    evens = 0

    while x>0:
    robot = random.choice(['剪刀', '石头', '布'])
    player = random.choice(['剪刀', '石头', '布'])
    print(f'robot show {robot}, player show {player}', end="")
    if(robot==player):
    evens += 1
    print(f" player and robot are even! 平手了{evens}次")
    elif(robot=="剪刀" and player=="布" ):
    wins += 1
    print(f"________robot is win! times:{wins}")
    elif(robot=="布" and player=="石头" ):
    wins += 1
    print(f"________robot is win! times:{wins}")
    elif(robot=="石头" and player=="剪刀" ):
    wins += 1
    print(f"________robot is win! times:{wins}")
    else:
    bads += 1
    print(f" robot is bad! times:{bads}")
    x-=1
    print("Done!")
  • 相关阅读:
    Storm应用系列之——集成Kafka
    Storm常见模式——分布式RPC
    Storm常见模式——流聚合
    博客迁移
    设计模式学习笔记
    JStorm模型设计
    MySQL学习笔记
    JAVA学习笔记
    JavaScript学习笔记
    用ACE来写代码
  • 原文地址:https://www.cnblogs.com/base/p/15109617.html
Copyright © 2011-2022 走看看