-1
So I’m trying to make a very simple calculator, (one of my first "projects"). In this calculator you need to choose an operation. Each operation has an associated number, and I use if and Elif to make the choice of the operation. However, when choosing the operation using input, at the time of the application check the chosen values, it says that the variable in this case y has not been defined. Edit: The problem has been solved but now it’s another problem in which after choosing the numbers the program doesn’t do the math and simply ends.
y = input('.:')
n1 = float(input("Primeiro Número "))
n2 = float(input("Segundo Número "))
if y == 1:
print(n1, "+" ,n2, "=" (n1+n2))
if y == 2:
print(n1, "-" ,n2, "=" (n1-n2))
elif y == 3:
print(n1, "x" ,n2, "=" (n1*n2))
if Y == 4:
print(n1, "/" ,n2, "=" (n1/n2))
calc()
In the last if, y is uppercase. python is case sensitive, so it interprets it as a new variable, which has not yet been defined.
– G. Bittencourt
Ah, it makes sense, thanks for the help, I hadn’t noticed
– Nuckhouse
Solved this error, but now there is another problem... After choosing the numbers the application does not do the math, the app simply ends.
– Nuckhouse
@Nuckhouse Probably the program ends and the window immediately closes without giving time to see the result. Try to put a
input()
at the end, after all they
.– Pedro von Hertwig Batista