SyntaxError = Invalid Syntax in variable name

0
LadodoQuadrado = input("Digite o valor correspondente ao lado de um quadrado: "
variavel = float(LadodoQuadrado)

x = LadodoQuadrado * 4

y = LadodoQuadrado ^ 2

print("perímetro:", x, "área:", y)

When I have run the program, it says "SyntaxError: invalid syntax" in the variables, every hour changes the variable that gives error. Can anyone help me?

    
asked by anonymous 26.04.2017 / 02:33

2 answers

1

This syntax error is because a parenthesis is missing at the end of input .

After resolving this error, the script will still return another error

  

TypeError: unsupported operand type (s) for ^: 'str' and 'int'

This is because the return of input is a string , that is, you need to convert the user input to a number and then try to do some math with it.

I put a direct conversion using int(input("")) , however, keep in mind that this will cause an error if the user enters any value that is not exactly a number (if the value is "Walkyrien", for example).

LadodoQuadrado = int(input("Digite o valor correspondente ao lado de um quadrado: "))
variavel = float(LadodoQuadrado)

x = LadodoQuadrado * 4

y = LadodoQuadrado ^ 2

print("perímetro:", x, "área:", y)

For knowledge purposes, a way to do this by treating user input

strEntrada = input("Digite o valor correspondente ao lado de um quadrado: ")

try:
    LadodoQuadrado = int(strEntrada)
except ValueError:
    print('entre com um número inteiro')
    exit()

variavel = float(LadodoQuadrado)

x = LadodoQuadrado * 4

y = LadodoQuadrado ^ 2

print("perímetro:", x, "área:", y)
    
26.04.2017 / 14:25
0
The python operator is not "^", but "**" or pow (x, y) if you want to use the math library function.

    
19.12.2017 / 16:43