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)