相关疑难解决方法(0)

浮点数学是否破碎?

请考虑以下代码:

0.1 + 0.2 == 0.3  ->  false
Run Code Online (Sandbox Code Playgroud)
0.1 + 0.2         ->  0.30000000000000004
Run Code Online (Sandbox Code Playgroud)

为什么会出现这些不准确之处?

language-agnostic math floating-point floating-accuracy

2798
推荐指数
28
解决办法
28万
查看次数

与变量一起使用的10e表示法?

我想知道如何在python 2.7.9中使用带有变量的10eX表示法。就字面量而言,10eX给出(10 ^ X).00000(浮点数)。我想使用一些变量而不是文字,但是它不起作用。如果有可能或应该采取其他方法,我应该进行什么语法更改?提前致谢!

T = int(raw_input())
while T:
    N = int(raw_input())
    LIS = map(int,raw_input().split())
    num_lis, num = []*N, []*N
    low = int(10e+(N))
    high = int(10e+(N+1))
    temp, count = 0, 0
    for i in xrange(low,high):
        num_lis = [1]*N
        temp = i
        while temp!=0:
            r = temp%10
            num[high-1-i] = r
            temp=temp/10        
        for p in xrange[1,N]:
            for q in xrange(0,p):
                if num[q]<num[p]:
                    if num_lis[p]<(num_lis[q]+1):
                        num_lis[p]=num_lis[q]+1
            if LIS[p]!=num_lis[p]:
                break
            else:
                count++
    print count
    T-=1
Run Code Online (Sandbox Code Playgroud)

运行解释器时出现错误-10e(N):语法无效

python floating-point python-2.7

3
推荐指数
1
解决办法
5092
查看次数