Problem with syntax error in else python

0

I'm having a problem with this code in Python where, when I try to run, it informs me that syntax error exists in a else . Here is the code and error below:

n=int(raw_input(''))
i=0

for i in xrange(0,n):
 num_poco=int(raw_input(''))
 tipo_do_poco=raw_input('')
 custo_poco=float(raw_input(''))


 if tipo_do_poco.upper() == P or tipo_do_poco.upper() == G:
    vazao=float(raw_input(''))
    enxofre=float(raw_input(''))
    if enxofre == E:
      taxa_enxofre=float(raw_input(''))
    elif enxofre != E:
      taxa_enxofre=0.0
 else: 
    vazao=0.0
    taxa_enxofre=0.0
    lucro=0.0
    receita=0.0
 print'============================================'
 print('Empresa de Perfuracoes Furo Certo S/A.')
 print('Poco no.: %d'%(num_poco))
 print('Custo do Poco                : R$%11.2f'%(custo_poco))

 if tipo_do_poco == P:
    print('Volume de Petroleo encontrado: %11.2f'%(vazao))
    receita = vazao * 5.50 * (1 - taxa_enxofre)  
 elif tipo_do_poco == G:
    print('Volume de Gas      encontrado: %11.2f'%(vazao))
    receita = vazao * 2.20 * (1 - taxa_enxofre) 
 else:
    print('Volume de          encontrado: %11.2f'%(vazao))
    receita = 0.00
 lucro=receita-custo_poco


 if (receita - custo_poco)>50000.00:    
     print('Lucro do Poco (gusher)       : R$%11.2f\n'%(lucro)        
 else:
     print('Lucro do Poco                : R$%11.2f\n'%(lucro)   
     #print('============================================')
     #print('') 

 custo_total = (total_custo+custo_poco): 
 total_receita = (total_receita+receita): 
 total_lucro = (total_lucro+lucro):
print('=======================================')
print"Empresa de Perfuracoes Furo Certo S/A."
print('Total de Pocos          : %d'%(num_poco)
print('Total dos Custos        : R$%11.2f'%(total_custo)
print('Total da Receita        : R$%11.2f'%(total_receita)
print('Total do Lucro          : R$%11.2f'%(total_lucro)
print('=======================================')
  

Traceback (most recent call last): File "python", line 41       else: print ('Profit of Little: R $% 11.2f \ n'% (profit)          ^ SyntaxError: invalid syntax

    
asked by anonymous 26.09.2017 / 01:57

2 answers

3

Syntax errors you just read the message that will know what is wrong: the error points to line 41 and if there is something wrong with this line, see the line above. In this case, one of the parentheses of line 40 were closed.

print('Lucro do Poco (gusher)       : R$%11.2f\n' % (lucro)) 
# (faltou este parenteses) --------------------------------^

In addition, I'd like to list other errors:

  • The same error mentioned above on line 42;
  • Two dots remaining on lines 46, 47 and 48;
  • Relatives also missing on lines 51, 52, 53 and 54;
  • In line 10, there are characters that were not properly defined as strings :

    if tipo_do_poco.upper() == "P" or tipo_do_poco.upper() == "G":
    
  • The same problem of 4 happens in lines 13, 15, 27 and 30;

  • It does not make sense for you to set the variable enxofre to float on line 12 and then compare it with strings ;
  • The elif of line 15 is completely unnecessary and can be replaced with a else ;
  • No raw_input has the identification to the user of which data is being read;
  • The indentation of the code is completely wrong and inconsistent; always try to use 4 spaces for each level of indentation;
  • The variable total_custo is used in line 46, but it is not defined in the code;
  • Same for variable total_receita on line 47;
  • E for the variable total_lucro on line 48;
  • At line 52 you display the variable total_custo , but only set custo_total ;
  • Correct this and the program (probably) will run without errors - which does not mean that it is correct.

        
    26.09.2017 / 02:32
    2

    Arthur, when you use % to demarcate where you want the value of a certain variable within your print it should follow the following syntax:

    print('quero falar dessa % variável ' %(variavel))
    

    In your case, the parentheses were omitted at the end. So this is showing the syntax error.

        
    26.09.2017 / 02:05