我想知道如何在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
在运行解释器时,我得到错误 - 10e(N):语法无效
答案 0 :(得分:5)
10e+4
是10 * 10^4
的表示法,不是操作。你必须使用幂运算符:
low = 10 ** (N+1)
high = 10 ** (N+2)
答案 1 :(得分:0)
10e3
之类的东西是浮点文字。您可以将其创建为字符串,然后使用float()
将其转换为数字(如果您想将该数字转换为int,则使用int(float())
):
>>> N = raw_input()
3
>>> float("10e"+N)
10000.0
>>> #compare:
>>> 10e3
10000.0
使用@Daniel的答案可能更好,但上面似乎更接近你试图用int(10e+(N))
做的事情,因为你明确询问了依赖于变量的文字。