I try to show in an array that a value is peak (it is greater than the number to its right and to its left) python [on hold]

-1

I am learning to use binary trees, the problem is that I have a basic error that I do not know how to solve, I am new to Python:

print('ingresa el rango del array:')
rango=int(input())
array=[]

for i in range(rango):
    print ('ingresa el numero de la casilla', i+1,':')
    num=int(input())
    array.append(num)

mitad = rango/ 2

if (array[mitad]<array[mitad-1]):
    for i in range([0],range(mitad-1)):           
        if(array[i-1]== None and array[i+1]<array[i]):
            print (i,'es pico')
        elif(array[i-1]<array[i] and array[i+1]<array[i]):
            print (i,'es pico')
        elif(array[i+1]== None and array[i-1]<array[i]):
            print (i,'es pico')
        else:
            print('no hay pico')

elif (array[mitad]<array[mitad+1]):
    for i in range([0],range(mitad-1)):
        if(array[i-1]== None and array[i+1]<array[i]):
            print (i,'es pico')
        elif(array[i-1]<array[i] and array[i+1]<array[i]):
            print (i,'es pico')
        elif(array[i+1]== None and array[i-1]<array[i]):
            print (i,'es pico')
        else:
            print('no hay pico')
else:
    print(array[mitad],'es pico')

Traceback (most recent call last):   File "Main.py", line 4, in     range = int (input ()) EOFError: EOF when reading a line ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ It's the first error

    
asked by jose cabrera 18.09.2018 в 11:28
source

1 answer

0

according to what is python, in

    if (array[mitad]<array[mitad-1]): #Sobran los parentesis

and in

    elif (array[mitad]<array[mitad+1]): #Aca tambien sobran

the correct code would be, according to what I know:

    if array[mitad]<array[mitad-1]: #No tiene parentesis
    elif array[mitad]<array[mitad+1]: #Aca tampoco hay parentesis

In logical sequences, the code is not written in parentheses () I hope you find it useful

Edition: I have just been told that parentheses are optional

    
answered by 18.09.2018 в 21:50