草庐IT

20230304

全部标签

Python程序笔记20230304

抛硬币实验random模块importrandomrandom.randint(a,b)返回一个随机整数N,范围是:arandom.choice("ilovefishc")从"ilovefishc"这个字符串中随机选出一个字符。编写一个双色球的开奖模拟程序importrandomred=random.sample(range(1,34),6)blue=random.randint(1,16)print("开奖结果是:",*red)print("特别号码是:",blue)至于 *red,其实大家写 red 也是OK的,就是显示结果会多一个“方框”:它其实是一个“解包”的操作,就是将框框里面的东西

Python程序笔记20230304

抛硬币实验random模块importrandomrandom.randint(a,b)返回一个随机整数N,范围是:arandom.choice("ilovefishc")从"ilovefishc"这个字符串中随机选出一个字符。编写一个双色球的开奖模拟程序importrandomred=random.sample(range(1,34),6)blue=random.randint(1,16)print("开奖结果是:",*red)print("特别号码是:",blue)至于 *red,其实大家写 red 也是OK的,就是显示结果会多一个“方框”:它其实是一个“解包”的操作,就是将框框里面的东西