Python conditional deviation

0

I made this code, but it does not compile. I'm using Visual Studio 2015 .

# Exercicio Python 2.6
import utf8

#PROGRAMA TESTE DOS IFS

#Usando Coding para assento nas Strings

input ("Digite valor de A ")
input ("Digite valor de B ")
input ("Digite valor de C ")
#TESTE
if (a > b):
    if (a > c):
         print("valor maior que A  " .a)
    else:
         print("valor Menor que A  " .c)
         # Else sempre tem que ter os : como assentuacaoo final
else:
    if (b > c):
    print("O maior valor B  ".b)
else
    print("O maior valor C  ".c)
    
asked by anonymous 05.04.2017 / 18:26

1 answer

5

Syntax

Let's first start with syntax errors.

import utf8

input ("Digite valor de A ")
input ("Digite valor de B ")
input ("Digite valor de C ")

if (a > b):
    if (a > c):
         print("valor maior que A  " .a)  #(1)
    else:
         print("valor Menor que A  " .c)  #(2)
else:
    if (b > c):
    print("O maior valor B  ".b)          #(3)
else                                      #(4)
    print("O maior valor C  ".c)          #(5)
  • The Python language allows you to use any number of whitespace for indentation as long as it is constant throughout your code. That is, if in one place you use 4 spaces (recommended by PEP 8 ), all indents in the code should be 4 spaces. In #(1) and #(2) the indentation has 5 spaces, which will generate error.

  • The Python language uses indentation as logical block delineators. That is, while the C language, for example, uses the {} characters to define what is within a conditional block, Python uses the indentation, so in #(3) , #(4) and #(5) , an indentation of 4 spaces will be required. Also,% w / w% was missing% w / w% after% w / w%.

  • Semantics

    Now to the semantic errors (that is, the code is completely formatted according to the Python standards, but will not work for logical errors).

    import utf8                               #(6)
    
    input ("Digite valor de A ")              #(7)
    input ("Digite valor de B ")              #(8)
    input ("Digite valor de C ")              #(9)
    
    if (a > b):
        if (a > c):
            print("valor maior que A  " .a)   #(10)
        else:
            print("valor Menor que A  " .c)   #(11)
    else:
        if (b > c):
            print("O maior valor B  ".b)      #(12)
        else:
            print("O maior valor C  ".c)      #(13)
    
  • The #(4) library with : is not native to Python - and I've particularly never heard of any with this name. If it is really a library, ensure that it is properly installed and in the same version of Python that it is running. If you only want to declare the encoding used in the code, use the else header. Read more at PEP 263 .

  • In utf8 , #(6) , and # -*- coding: utf-8 -*- you use the #(7) function to prompt the user for values of A, B, and C. Problems:

    4.1. Even if the user enters the three values, they are not stored anywhere. You should, if you want to use the value entered, store it in a variable.

    4.2. It is not recommended to use the #(8) function in Python versions 2.6 and 2.7. The ideal is to use #(9) and convert the value to integer after: input .

  • In input , raw_input , int(raw_input("...")) and #(10) you concatenate strings with the #(11) character. I believe this is the PHP language standard. In Python, the #(12) operator is used or the string is formatted. If you do the concatenation, take care of the type of the variable, as it will not be possible to concatenate a string with an integer.

  • 05.04.2017 / 19:29