1
I started using Python recently and am creating a calculator to train factors like function, input and function return within another function.
However, my calculator is not working, it simply does not return anything. It seems that it does not enter the if
, even though the option is receiving the value.
Could help me identify the mistake?
def calculadora():
print("Ola! \n" "Bem vindo a calculadora digital em python! \n" "Por favor, digite a opcaoo:")
print("Opcao 1: Soma \n Opcao 2: Subtracao \n Opcao 3: Multiplicacao \n Opcao 4: Divisao")
opcao = input()
if opcao == 1:
print("Vamos somar!")
return soma()
elif opcao == 2:
print("Vamos subtrair!")
return subtracao()
elif opcao == 3:
print("Vamos Multiplicar!")
return multiplicacao()
elif opcao == 4:
print("Vamos Dividir!")
return divisao()
def multiplicacao():
print("Agora, digite os valores a serem usados para a multiplicacao")
n = input()
m = input()
return print("O resultado eh: ", n*m)
def soma():
print("Agora, digite os valores a serem usados para a soma")
n = input()
m = input()
return print("O resultado eh: ", n+m)
def subtracao():
print("Agora, digite os valores a serem usados para a subtracao")
n = input()
m = input()
return print("O resultado eh: ", n-m)
def divisao():
print("Agora, digite os valores a serem usados para a divisao")
n = input()
m = input()
return print("O resultado eh: ", n/m)
calculadora()
opcao = int(input())
– Augusto Vasques
As @Augustovasques said, put
opcao = int(input())
, for theinput()
returns astring
, so you have to put theint()
to convert the value tointeiro
– Codigo de Senior
If this answer solved your problem and there is no doubt left, mark it as correct/accepted by clicking on the " " that is next to it, which also marks your question as solved. If you still have any questions or would like further clarification, feel free to comment.
– Codigo de Senior