小编Mat*_*Cao的帖子

项目欧拉#11 Numpy方式

网格中最大的产品

问题11

在下面的20×20网格中,沿对角线的四个数字标记为红色.

这些数字的乘积是26×63×78×14 = 1788696.

在20×20网格中,相同方向(上,下,左,右或对角)的四个相邻数字的最大乘积是多少?

x ='''
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
52 70 95 23 04 60 11 42 69 24 68 …
Run Code Online (Sandbox Code Playgroud)

python numpy pandas

5
推荐指数
1
解决办法
172
查看次数

如何将数字舍入为10,100,1000,10000,100000

我想要一个函数,如果它小于10,则将数字舍入为10,如果它在10到1000之间,则舍入为100,依此类推.

这将有助于数字连接问题,所以我不必将数字转换为str和back.

def roundup(n):
    if n < 0: return 0
    if n < 10: return 10
    if n < 100: return 100
    if n < 1000: return 1000
    if n < 10000: return 10000
Run Code Online (Sandbox Code Playgroud)

我想知道是否有一种自然的方法来做到这一点,而不只是将'if'放在一起

python integer roundup

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

标签 统计

python ×2

integer ×1

numpy ×1

pandas ×1

roundup ×1