r/PythonLearning • u/Lestafan69 • Oct 27 '24
Why isnt this working?
Yes I know I can print screen but i cant be bothered to log in on the laptop
12
u/Electrical_Seaweed11 Oct 27 '24
I think what you're looking for is:
if operator == "-":
...The difference being, quotes around the minus sign, since it's treated as a str
10
Oct 27 '24
Bro please take a screenshot and rotate the picture, this is laziness on a whole new level
0
5
u/Rageinjector Oct 27 '24 edited Oct 27 '24
Brand new to python but I see a few things. Your - should be in quotes(single or double, your choice) in your if line, also the colon should be immediately after the last character of whatever you type on any line, no space. .. You may also want to write it as a f-string
if operator == "-":
print(f"The answer to {num1} {operator} {num2} is {num1 - num2}")elif operator == "+":
print(f"The answer to {num1} {operator} {num2} is {num1 + num2}")Etc.
Edit: formatting from mobile
2
u/HeadlineINeed Oct 27 '24
Cause - isn’t set as a string. Only bools, ints, and floats are non-strings.
Throw - in “” and it should work
1
u/Python_Puzzles Oct 27 '24
The input() returns a string, which is text inside " " quotes.
if operator = "-" is what you are looking for.
Also, please copy and paste any future code into these posts so we can copy and paste it as well. Reddit has "code blocks" from markup language to help you do this.
3
u/Lestafan69 Oct 27 '24
Thank you for everyone's help