小编Tho*_*hom的帖子

Python舍入到最接近的0.25

我想将整数舍入到最接近的0.25十进制值,如下所示:

import math

def x_round(x):
    print math.round(x*4)/4

x_round(11.20) ## == 11.25
x_round(11.12) ## == 11.00
x_round(11.37) ## == 11.50
Run Code Online (Sandbox Code Playgroud)

这在Python中给出了以下错误:

Invalid syntax
Run Code Online (Sandbox Code Playgroud)

python math rounding python-3.x

3
推荐指数
2
解决办法
4681
查看次数

Python 从列表中选择 20 个随机结果

我想从以下列表中获得 20 个随机结果:

coordinates = [
  [20, 140], [40, 140], [60, 140], [80, 140], [100, 140], [120, 140],
  [20, 120], [40, 120], [60, 120], [80, 120], [100, 120], [120, 120],
  [20, 100], [40, 100], [60, 100], [80, 100], [100, 100], [120, 100],
  [20, 80], [40, 80], [60, 80], [80, 80], [100, 80], [120, 80],
  [20, 60], [40, 60], [60, 60], [80, 60], [100, 60], [120, 60],
  [20, 40], [40, 40], [60, 40], [80, 40], [100, 40], [120, 40]
]
Run Code Online (Sandbox Code Playgroud)

我试过了, …

python random

-1
推荐指数
2
解决办法
5935
查看次数

标签 统计

python ×2

math ×1

python-3.x ×1

random ×1

rounding ×1