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!")
  • 相关阅读:
    机器学习的定义和分类
    选股
    mysql修改密码
    快速排序
    php的错误类型
    MySQL数据库优化
    库存超卖问题
    循环处理
    kafka安装配置
    JavaScript、jQuery杂记
  • 原文地址:https://www.cnblogs.com/base/p/15109617.html
Copyright © 2011-2022 走看看