syntax error in python 3?

1

Why does syntax error appear when executing this block? I can not find the reason:

 for Empleados in cursor:
     emplead = '\t'+ str(Empleados[0]) + '\t'+ str(Empleados[1]) + '\t' + 
     str(Empleados[2]+ \
     '\t' + str(Empleados[3] +'\t' + str(Empleados[4] + '\t' + str(Empleados[5] 
     + '\t' + str(Empleados[6])
     print (str(emplead))

This is the error that shows me:

print (str(emplead))
        ^
SyntaxError: invalid syntax

The chain is 2 lines, I appreciate guidance.

    
asked by Jsierra2017 13.07.2017 в 23:46
source

3 answers

2

The error was because you failed to close some of the calls to the function str() and that usually happens when you concatenate in that way. A simpler way to do this is by formatting the text string:

for Empleados in cursor:
     emplead = '\t%s\t%s\t%s\t%s\t%s\t%s\t%s' % (
         Empleados[0],
         Empleados[1],
         Empleados[2],
         Empleados[3],
         Empleados[4],
         Empleados[5],     
         Empleados[6]    
     ) 
     print(emplead)

Now it looks more ordered than before and it is easier to read as well.

    
answered by 14.07.2017 / 00:24
source
5

The error is due to having closed parentheses as César says. These errors are easier to commit in lines as long as that, in addition to making the code little legible. You can use the str.format method and simplify the code a lot:

for Empleados in cursor:
    emplead = '\t{}\t{}\t{}\t{}\t{}\t{}\t{}'.format(*Empleados)
    print(emplead)
    
answered by 14.07.2017 в 00:26
0
def func(N):
    i = 0
    while (2 ** i < N):
        i = i + 1
    return i


print(func(64))

Hello it's already good but I have another problem because I'm a result of 7 and I need 6 as I do.

    
answered by 05.08.2018 в 04:12