Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

10e notation used with variables?

I want to know how can I use the 10eX notation in python 2.7.9 with a variable. In terms of literals 10eX gives (10^X).00000(floating point number). I want to use some variable instead of literal, however, and it does not work. What syntactical change should I make if it is possible to do so or is there any other way to do so? Thanks in advance!

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

On running the interpreter I get error for- 10e(N) : Invalid Syntax

like image 433
Nishit Mengar Avatar asked Dec 14 '22 01:12

Nishit Mengar


2 Answers

10e+4is a notation for 10 * 10^4, not an operation. You have to use the power-operator:

low = 10 ** (N+1)
high = 10 ** (N+2)
like image 164
Daniel Avatar answered Jan 08 '23 19:01

Daniel


Something like 10e3 is a float literal. You could create it as a string and then use float() to convert it to a number (and int(float()) if you wanted to convert that number to an int):

>>> N = raw_input()
3
>>> float("10e"+N)
10000.0
>>> #compare:
>>> 10e3
10000.0

It is probably better to use the answer of @Daniel, but the above seems closer to what you were trying to do with int(10e+(N)) since you were explicitly asking about literals which depend on variables.

like image 37
John Coleman Avatar answered Jan 08 '23 18:01

John Coleman