0
Help, I'm trying to make a calculator but it's not working
user_input1=float(input("")) #defining first Number operation=(input("")) #multiply, divide, add, subtract user_input3=float(input("")) #defining second number if operation==("*"): #if/elif statements to read what operation the user has inputed a= user_input3 * user_input1 elif operation==("+"): a=user_input1 + user_input3 elif operation==("-"): a=user_input1 - user_input3 #if statement is correct it defines a as the operation elif operation==("Ă·"): a=user_input1 // user_input3 print(user_input1,operation,user_input3,"=",a) For some reason when I divide it says that a isn't defined when it's clearly defined.
6 Answers
+ 3
try to change the division symbol to slash "/"
It's hard to find "Ă·" symbol on the phone, and there is no "Ă·" on the PC keyboard. maybe it's some special symbol and python doesn't recognise it
Update: found what's wrong. run this code and type Ă· when prompted:
a = input('type Ă· : ')
print('inner: Ă·')
print('outer:'+a)
and you will see that when you type Ă· symbol as input, it stays the same, but python (maybe only in this app, and maybe everywhere) doesn't seem to know this symbol when printing it, replacing it with double ~. somehow the codes of Ă· is different in this two cases.
+ 1
Try this simpler alternative of a calculator:
print("Calculator")
x = input("")
xy = input("")
y = input("")
if xy == "+":
print(x+y)
elif xy == "-":
print(x-y)
elif xy == "*":
print(x*y)
elif xy == "/":
print(x/y)
else:
print("SYNTAX ERROR")
Plus, does anyone knows how to output to one line?
0
is it only when u divide ?
or with every operation
0
Just dividing, which is weird because it's the same as every other operation.
0
The idea is if the user input's 'Ă·' then it would define 'a' as dividing the first number by the second number and the next line was printing the outcome. But literally for only dividing it doesn't define a for some reason.
0
The symbol for dividing is '//' and I've tested it by dividing two numbers with that symbol and it worked. For some reason it doesn't recognize 'a' as a defined function when you can see (on the last elif) it defines 'a' as the division between user_input1 and user_input2.
The idea is if "operation" is inputed as "Ă·" it then defines 'a' as user_input1 // user_input2 and thus prints it as such. The division symbol itself is irrelevant because it's a string.
The error message says 'a' isn't defined.
Maybe it just doesn't work in mine? Idk.
Try using it on yours maybe and change the "Ă·" to your division symbol since it may be different from mines and see if it works. As long as it works at all and I'm not being a dummy I'm good lol.
Update: @Dmitriy Silkin, IT WORKED?!? I DON'T UNDERSTAND, HOW DOES CHANGING THE SYMBOL WORK??? THANK YOU SO MUCH
I honestly don't understand though, how does it work? That shouldn't work because of that and if it does then how??? I don't get it lol. Thank you so much, again, this bug has been really bothering me.