weixin_51573847 2021-10-26 12:04 采纳率: 77.3%
浏览 41
已结题

Python实现相加为奇数则用户赢,如果并且用户能自行选择退出游戏,且计算他们的分数

Consider a game, where both the computer and the user come up with a number. (想出一个游戏,用户和电脑都出一个数字)
a. If both the numbers sum up to an even number, the player wins and the message is displayed. (如果两个数字相加为偶数,则玩家获胜,并且print)
b. The game keeps repeating until the player decides to quit (游戏持续进行,知道玩家决定退出,按q退出游戏)
C. Let's keep a score of who won how many times. Display(print) the score on quit. (计算玩家和电脑分别获胜的次数,并且在按q退出之后显示成绩)

在学python课时候遇到的一个麻烦

  • 写回答

3条回答 默认 最新

  • 辉煌仪奇 2021-10-26 12:09
    关注
    import random
    
    users = 0
    computers = 0
    while True:
        print("Game started")
        computer = random.randint(1, 100)
        user = input("put a number here,hit q to exit")
        if user == "q":
            break
        user = int(user)
        if (computer + user) % 2 == 0:
            users += 1
            print("user win")
        elif (computer + user) % 2 != 0:
            computers += 1
            print("Computer win")
    print("user win:",users,"Computer win:",computers)
    

    有帮助请采纳,有问题继续交流,你的采纳是对我回答的最大的肯定和动力

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 11月3日
  • 已采纳回答 10月26日
  • 赞助了问题酬金 10月26日
  • 创建了问题 10月26日

悬赏问题

  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C