+ 2

Why's there an error

I need help with the calculator that im making and there's an error in line 4 and idk why https://sololearn.com/compiler-playground/cOuhypuQs3Cs/?ref=app

25th Jun 2025, 8:41 AM
Abdulrahman alturk
Abdulrahman alturk - avatar
12 Answers
+ 2
Abdulrahman alturk +,-,*,/ are strings in your code so they should be enclosed with quotations. And it's "==" not "=" while comparing.
25th Jun 2025, 8:50 AM
Manav Roy
Manav Roy - avatar
+ 7
Abdulrahman alturk , just allow me a comment. the second line (that is used for an operator sign): equation_type = str(input()) does not require the str() function, since all inputs in python are strings by default. so we can just use: equation_type = input()
25th Jun 2025, 9:37 AM
Lothar
Lothar - avatar
+ 3
Artena , => “Solve “ is not Not defined ٫ You must define it in advance so that the answer can be stored in it and then displayed. the above statement is not quite correct for python. the code works correctly if the line: solve=0 is removed or is commented out.
26th Jun 2025, 12:26 PM
Lothar
Lothar - avatar
+ 2
+ is not a string. "+" is a string. same goes for the other operators in the comparisons.
25th Jun 2025, 8:42 AM
Lisa
Lisa - avatar
+ 2
Guys ok i get it thanks guys
25th Jun 2025, 5:42 PM
Abdulrahman alturk
Abdulrahman alturk - avatar
+ 1
still no difference
25th Jun 2025, 8:44 AM
Abdulrahman alturk
Abdulrahman alturk - avatar
+ 1
Thanks 😊
25th Jun 2025, 8:53 AM
Abdulrahman alturk
Abdulrahman alturk - avatar
+ 1
a = float(input()) equation_type = str(input()) b = float(input()) solve=0 #or you can save it in a list (solve=0) if equation_type == '+' : solve = a+b elif equation_type == '-' : solve = a-b elif equation_type == '*' : solve = a*b elif equation_type == '/' : solve = a/b elif equation_type == '^' : solve = a**b print() print() print("_____________________________________") print("the answer is equal to" + " " + str(solve)) “Solve “ is not Not defined ٫ You must define it in advance so that the answer can be stored in it and then displayed. Line 4 And in this program you should write like this For example: 2 + 2 And it will give you the answer
25th Jun 2025, 1:33 PM
Artena
Artena - avatar
+ 1
Take all the input in one line. Like this : a, equation_type, b = input("Enter a operator b: ").split() a = float(a) b = float(b) # There will be no error now
26th Jun 2025, 2:55 PM
Md Mehedi Hasan
Md Mehedi Hasan - avatar
0
Use two = symbols in if statements. By the way if you wanna get advanced in python then you should try making a complex project like (this code is totally not fake) https://sololearn.com/compiler-playground/c6l8CNwt0gTZ/?ref=app
25th Jun 2025, 8:53 AM
Vaibhav
Vaibhav - avatar
0
Use this method def addition(x, y): return x + y def soustraction(x, y): return x - y def multiplication(x, y): return x * y def division(x, y): if y == 0: return "Erreur : Division par zéro !" return x / y def calculatrice(): print("Calculatrice simple") print("1. Addition") print("2. Soustraction") print("3. Multiplication") print("4. Division") print("5. Quitter") while True: choix = input("Choisissez une option : ") if choix == "1": x = float(input("Entrez le premier nombre : ")) y = float(input("Entrez le deuxième nombre : ")) print(f"{x} + {y} = {addition(x, y)}") elif choix == "2": x = float(input("Entrez le premier nombre : ")) y = float(input("Entrez le deuxième nombre : ")) print(f"{x} - {y} = {soustraction(x, y)}") elif choix == "3": x = float(input("Entrez le premier nombre : "))
26th Jun 2025, 3:17 PM
Noumen Kevin
Noumen Kevin - avatar
0
This is not java, there's no need to make extra boilerplate "methods"
26th Jun 2025, 4:23 PM
Vaibhav
Vaibhav - avatar
OSZAR »