服务市场
  • 交易市场
  • 平台大厅
  • 下载市场
  • 收录信息
  • A保平台
    平台客服
    微信Q群
    浏览记录



    平台微博/weibo    平台微信/公众号    平台抖音/快手   
    曝光台    保障    地图   
    A保站    登录      |  注册  |  

    只需一步,快速开始!

     找回密码   |   协议
    热门搜索: 网站开发 App报毒 挖矿源码 代办资质

    二级考试课后题 习题4

    • 时间:2020-10-28 23:41 编辑:敲代码的小风 来源: 阅读:846
    • 扫一扫,手机访问
    摘要:
    """ 
    def judgeLeapYear(year):
        if year % 400 == 0:
            print("闰年")
            return
        elif year%100!=0 and year%4==0:    
            print("闰年")
            return
        else:
            print("平年")
            return
    
    year = eval(input("请输入年份..."))
    judgeLeapYear(year) """
    
    
    """ 
    def greatest_common_divisor(a,b):
        big, small = max(a,b), min(a,b)
        if big % small == 0:
            return small
        else:
            return greatest_common_divisor(small,big-small)
    
    def least_common_multiple(a,b):
        result = a*b/greatest_common_divisor(a,b)
        return result
    
    a = eval(input("请输入第一个数字..."))
    b = eval(input("请输入第二个数字..."))
    print("最大公约数: #",greatest_common_divisor(a,b))
    print("最小公倍数: #",least_common_multiple(a,b))
    
     """
    
    """ 
    strInput = input("请输入一行字符...")
    cntCE = 0
    cntNum =0
    cntSpace = 0
    cntOther = 0
    for c in strInput:
        if chr(19968)<=c<=chr(40896):
            cntCE += 1
        elif "a" <= c <= 'z' or "A" <= c <= 'Z':
            cntCE += 1
        elif "0" <= c <= '9':
            cntNum += 1
        elif c == " ":
            cntSpace += 1
        else:
            cntOther += 1
    print(strInput)
    print("中英文",cntCE)
    print("数字",cntNum)
    print("空格",cntSpace)
    print("其他",cntOther) """
    
    
    
    """ 
    
    def getNum():
        while True:
            try:
                num = eval(input("请输入数字"))
                if type(num) != type(11):
                    print("输入内容必须为整数!")
                    continue
            except:
                print("输入内容必须为整数!")
                continue
            return num
    
    
    import random
    N = random.randint(1,1000)
    # N = 900
    cnt = 0
    while True:
        num = getNum()
        cnt += 1
        if num == N:
            print("猜对了!!!")
            break
        elif num < N:
            print("猜小了!!!")
            continue
        elif num > N:
            print("猜大了!!!")
            continue
    print("猜测次数:#",cnt) """
    
    
    
    
    import random
    correct_changed = 0
    correct_unchanged = 0
    
    repeatNum = 200000000
    # repeatNum = 10000
    totalNum = repeatNum
    while (repeatNum > 0 ):
    
        doors = ["sheep","sheep","sheep"]
        index  = random.randint(0,2)
        doors[index] = "car"
    
        if doors[1] == "sheep" and doors[2] == "sheep":
            nextChoose = random.randint(1,2)
        elif doors[1] == "sheep":
            nextChoose = 2
        else:
            nextChoose = 1
    
        if doors[0]=='car':
            correct_unchanged += 1
        elif doors[nextChoose]=='car':
            correct_changed += 1
        repeatNum -= 1
    print("\n\n蒙特卡洛模拟数量:#{0:->23,}次".format(totalNum))
    print("选手更改选择的获胜概率:{0:->20,.8%}".format(correct_changed/totalNum))
    print("选手坚持选择的获胜概率:{0:->20,.8%}\n\n".format(correct_unchanged/totalNum))
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 全部评论(0)

    微信客服(速回)

    微信客服(慢回)



    企业微信客服二维码
    联系我们
    平台客服: 平台QQ客服

    平台电话:400电话迁移中!

    平台邮箱:28292383@qq.com

    工作时间:周一至周五:早10:00 晚:18:00

    营业执照     网站ICP备案:鲁ICP备20027607号     鲁公网安备:37068702000078号     增值电信业务经营许可证、在线数据与交易处理业务许可证:鲁B2-20200681      © 2016-2023 A保站  https://www.abaozhan.com/ 版权所有!      A保站平台规范:   关于我们   广告合作   隐私条款   免责声明   法律声明   服务条款   网站地图   平台工单!