-6

i have a problem i want to recover the minimum and maximum Values in another function args.parse ....

so my question why [minimum:maximum] is a

SyntaxError: invalid syntax

as the minimum and maximum can be input by User

def Z(Y,minimum,maximum):
    Y = [minimum:maximum]
    return Y

Help please

Maroun
  • 94,125
  • 30
  • 188
  • 241
user2504287
  • 47
  • 1
  • 1
  • 5

2 Answers2

0

This line is wrong:

Y = [minimum:maximum]

It should be a tuple or something else

Y = (minimum, maximum)

You can't create a datastructure in Python like this. It is a slice but can't be instantiated like this.

Noel Evans
  • 8,113
  • 8
  • 48
  • 58
0

I do not fully understand what you wanted to achieve but i think is one of the following 2:

1.return a continuous range of value between minimum and maximum. In this case you can use range and do not pass Y as input param.

def Z(minimum,maximum):
    Y = range(minimum, maximum)
    return Y

print Z(2,4)

2.you want to slice Y between value at index minimum and maximum. the use the following:

def Z(Y,minimum,maximum):
    Y = Y[minimum:maximum]
    return Y

Y = [1,2,3,4,5,6,7,8,9]    
print Z(Y,2,4)

from your comment i think you want to use the version 2. so you have simply forgot to put Y before [minimum:maximum]. you have to put Y to say that this is the variable to be sliced. have a nice explanation on how slice works here

Community
  • 1
  • 1
Stefano
  • 3,981
  • 8
  • 36
  • 66